How to get command line of UNIX process?
Is it possible to grab the command line that was used to invoke a process on Mac OS X?
Solution 1:
ps ax
shows you the command line of all running processes; you can grep for the pid you want.
Solution 2:
Does:
~$ ps ax | grep "ntp"
57 ?? Ss 0:04.66 /usr/sbin/ntpd -c /private/etc/ntp.conf -n
3104 s000 S+ 0:00.00 grep ntp
do what you need it to (change ntp to the program you are interested in)? This usually gives me the command-line arguments of running processes (I use to check what Launchd used when running a system daemon for example).
Solution 3:
cat /proc/$PROCESSNUMBER/cmdline | tr '\0' '\n'
Allthough it's Linux specific, it gets the commandline of process numbered $PROCESSNUMBER
straight from the kernel (the /proc/$PROCESSNUMBER/cmdline
part) and makes it readable by putting each argument on a separate line by translating (with tr -token
replace) the \0's into newlines (\n).
This line only works if you put a real processnumber of a running process (you can find one by running the command ps -ef
) in the $PROCESSNUMBER part!