|
在http://www.ddvip.com/OS/solaris/index4/12.htm中有这样一个程序:
/*
* @(#)memlook.c 1.0 10 Nov 1997
* Robert Owen Thomas robt@cymru.com
* memlook.c -- A process memory utilization reporting tool.
*
* gcc -Wall -O3 -o memlook memlook.c
*/
#pragma ident "@(#)memlook.c 1.0 10 Nov 1997 Robert Owen Thomas robt@cymru.com "
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <sys/syscall.h>
#include <sys/procfs.h>
#include <sys/param.h>
#include <unistd.h>
#include <fcntl.h>
int counter = 10;
int showUsage ( const char * );
void getInfo ( int, int );
int main ( int argc, char * argv[] )
{
int fd, pid, timeloop = 0;
char pidpath[BUFSIZ]; /* /usr/include/stdio.h: #define BUFSIZ 1024 */
switch ( argc )
{
case 2:
break;
case 3:
timeloop = atoi( argv[2] );
break;
default:
showUsage( argv[0] );
break;
} /* end of switch */
pid = atoi( argv[1] );
sprintf( pidpath, "/proc/%-d", pid ); /* -表示向左靠 */
if ( ( fd = open( pidpath, O_RDONLY ) ) < 0 )
{
perror( pidpath );
exit( 1 );
}
if ( 0 < timeloop )
{
for ( ; ; )
{
getInfo( fd, pid );
sleep( timeloop );
}
}
getInfo( fd, pid );
close( fd );
exit( 0 );
} /* end of main */
int showUsage ( const char * progname )
{
fprintf( stderr, "%s: usage: %s < PID > [time delay]\n", progname, progname );
exit( 3 );
} /* end of showUsage */
void getInfo ( int fd, int pid )
{
prpsinfo_t prp;
prstatus_t prs;
if ( ioctl( fd, PIOCPSINFO, &prp ) < 0 )
{
perror( "ioctl" );
exit( 5 );
}
if ( ioctl( fd, PIOCSTATUS, &prs ) < 0 )
{
perror( "ioctl" );
exit( 7 );
}
if ( counter > 9 )
{
fprintf( stdout, " ID\tIMAGE\t\tRSS\t\tHEAP\t\tSTACK\n" );
counter = 0;
}
fprintf( stdout, "%u\t%-9u\t%-9u\t%-15u\t%-15u\n", pid,
( unsigned int )prp.pr_bysize, ( unsigned int )prp.pr_byrssize,
( unsigned int )prs.pr_brksize, ( unsigned int )prs.pr_stksize );
counter++;
} /* end of getInfo */
我运行总是提示这个错误:
test@szxdb:~/lxy/pro> gcc -Wall -O3 -o memlook memlook.c
memlook.c: In function `getInfo':
memlook.c:74: `PIOCPSINFO' undeclared (first use in this function)
memlook.c:74: (Each undeclared identifier is reported only once
memlook.c:74: for each function it appears in.)
memlook.c:79: `PIOCSTATUS' undeclared (first use in this function)
memlook.c:90: structure has no member named `pr_bysize'
memlook.c:90: structure has no member named `pr_byrssize'
memlook.c:91: structure has no member named `pr_brksize'
memlook.c:91: structure has no member named `pr_stksize'
谁知道为什么?谢谢了。 |
|