Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Example using getproc()/getargs()

448 views
Skip to first unread message

Rachna patel

unread,
Mar 4, 1997, 3:00:00 AM3/4/97
to

OK, here is the example how to use getproc()/getargs to the questions I
have got an emails for.

***********************************************************************
#include <stdio.h>
#include <procinfo.h>
#include <locale.h>
#include <sys/time.h>

#define NPROCS 10000

/* system call to get process table */
extern getproc(struct procinfo *procinfo, int nproc, int sizproc);
/* procinfo: pointer to array of procinfo struct */
/* nproc: number of user procinfo struct */
/* sizproc: size of expected procinfo structure */

/* system call to get program arguments */
extern getargs(struct procinfo *procinfo, int plen, char *args, int
alen);
/* procinfo: pointer to array of procinfo struct */
/* plen: size of expected procinfo struct */
/* args: pointer to user array for arguments */
/* alen: size of expected argument array */
struct procinfo proc1[NPROCS];

main()
{
int nproc1;
int i;
char buf[8192];


nproc1 = getproc(proc1, NPROCS, sizeof(struct procinfo));
for (i = 0; i < nproc1; i++) /* get each user-area entrys by process */
{
getargs(&proc1[i], sizeof(struct procinfo),
buf,sizeof(buf));
buf[8192-1] = '\0';
printf("%d,%s",i,buf);
printf("%d,%.*s,\n",i,(int)20,&buf[strlen(buf)+1]);
}


}
***********************************************************************

Hope this helps.

Regards,
Rachna Patel.
rac...@iscp.bellcore.com

0 new messages