On Sep 1, 2009, at 7:55 AM, Rakesh Singhal < email@hidden> wrote: Hi all, I can find pid for any running process using code given here http://developer.apple.com/mac/library/qa/qa2001/qa1123.html. But I want to find the arguments passed to this running process, when it was launched. I checked the kinfo_proc structure but I could not find any thing related to arguments.
Thanks in advance.
char cmd[1024]; // xxx size sprintf(cmd, "/bin/ps -o args -p %d", pid); fp = popen(cmd, "r"); // now just read the arguments
...of course for traditional UNIX daemons, you just write your pid and arguments into a file in /var/run, go there, read the file, and kill(pid, 0); to check that the prcess is still valid.
In other words, you know their values because you remember them.
This also lets you distinguish arguments and commands with spaces in them from multiple arguments, if you write them to the file one per line.
-- Terry |