Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > List of processes with names?

List of processes with names?
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Santa Clara, CA 95050
Status: Offline
Reply With Quote
Apr 23, 2001, 06:16 PM
 
I was wondering if there is any way to get the PIDs of all the processes from the user-written code. I know that we can use the getpid() and getppid() to get the code for the current process and its parent. However, is there a way to get the PIDs of all the processes on the system? (source code for 'top'?

------------------
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 23, 2001, 08:28 PM
 
"man ps"

     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Apr 24, 2001, 09:05 AM
 
You could get the source code for top and try to manipulate the kvm functions... however, this is cumbersome.

Try a pipe to "ps" with arguments "wwwaux" (All processes, full name, &c.) Then scan the string to your liking.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Apr 24, 2001, 10:44 AM
 
Look at sysctl() ("man 3 sysctl"). More specifically, the CTL_KERN top-level name, and the KERN_PROC section under that.
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Apr 24, 2001, 10:45 AM
 
[Double post]

[This message has been edited by lindberg (edited 04-24-2001).]
     
simran  (op)
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Santa Clara, CA 95050
Status: Offline
Reply With Quote
Apr 24, 2001, 02:14 PM
 
Thank you for all your suggestions. I am looking at syscntl(). This seems to be useful. It has some really low level (neat) stuff which we can poke into. I am not sure, however, what permissions will my process have to have in order to read some of these variables. I will try and see how far will I get.
     
simran  (op)
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Santa Clara, CA 95050
Status: Offline
Reply With Quote
Apr 24, 2001, 02:23 PM
 
Is there a way to use the unix shell command from a C source? If yes, then I guess, piping the ps to a string will suffice. If not, then I probably have to us syscntl().

Thank you.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 24, 2001, 03:17 PM
 
here's some code I wrote a while ago just for learning how to use popen(). It's messy and probably lame, but hey, I think it kinda works

It uses ls but you can easily change this to your liking.

Code:
#include <stdio.h> #include <stdlib.h> int main(void) { int i; FILE *f; int c; char s[2500]; f = popen("ls","r"); if (f != NULL) { char mychar; for (i=0; i<2500; i++) if (!(feof(f))) s[i] = fgetc(f); printf("%s",s); } else { printf("Something went wrong somehwere."); } /* i = system("ls");*/ i = pclose(f); return 0; }
     
simran  (op)
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Santa Clara, CA 95050
Status: Offline
Reply With Quote
Apr 25, 2001, 05:38 PM
 
Thanks Angus. I tried the code. It works. Thank you all for the help.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2