Re: Find argument passed to running process
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com On 02.09.2009, at 10:07, Terry Lambert wrote: To actually answer the question, look at the source code for "ps": <http://developer.apple.com/mac/library/qa/qa2001/qa1123.html> Nico _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On Sep 1, 2009, at 9:38 PM, Stephen J. Butler wrote: On Tue, Sep 1, 2009 at 9:55 AM, Rakesh Singhal<rakesh.singhal@gmail.com
wrote:
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. <http://www.opensource.apple.com/source/adv_cmds/adv_cmds-119/ps.tproj/ps.c
It calls sysctl with { CTL_KERN, KERN_PROC, what, flags } (look a little higher up for what gets stuffed in those vars). From the result, it then looks at "kp[i]->kp_proc->p_comm" (saveuser function). "The UNIX Programming FAQ lists a number of alternative ways to do this. Of these, the only approach that works on Mac OS X is exec'ing the ps command line tool. exec'ing ps will require parsing the tool's output and will not use system resources as efficiently as Listing 1." ...on the other hand, the ps method is more likely to continue to work in future versions of the OS. Also note that qa is 7 or 8 years old, based on how you read the dates. The problem with parsing the output of ps is that it only works with the most harmless arguments. If a command line argument contains funny characters like a line feed for example it will show up as "^M" in ps's output. I always wondered why there is no way to get the information ps delivers in a library function. Parsing output may have worked in the days where a Unix user would not even imagine putting anything but printable non-whitespace characters in a file name. This email sent to site_archiver@lists.apple.com
participants (1)
-
Nico Schmidt