Operating System - Linux
1748202 Members
3113 Online
108759 Solutions
New Discussion

Receive processes list from С code

 
SOLVED
Go to solution
Vadim Yezhakov
Advisor

Receive processes list from С code

Hi.
How can i receive current processes list (like as 'ps') from my application. I know how use pstat() system call, but it not show info about all processes at one time.
3 REPLIES 3
Muthukumar_5
Honored Contributor
Solution

Re: Receive processes list from С code

see pstat(2) man page. Several example are there with code in the man page itself.

hth.
Easy to suggest when don't know about the problem!
Vadim Yezhakov
Advisor

Re: Receive processes list from С code

Thanks :)

I thinked, that pstat_getproc() return info about process from with it was called.

It was incorrect meaning.
Rory R Hammond
Trusted Contributor

Re: Receive processes list from С code

Vadim,

Long time ago I cheated because the PS structure had changed between OS's.
So I used popen() and put the output into a structure. I then parsed the results.
Attached is sample program that walks the process tree showing parent and childern.

pswalk PID

try a couple PID's if the Number is to low
like the parent PID of inetd, It would be able to walk up the very far.

I see a problem with the one define:
#define CMD "ps -fe|grep -v STIME"

The ps and grep, should have a full path name.

Rory


There are a 100 ways to do things and 97 of them are right