8
3
Is it possible to grab the command line that was used to invoke a process on Mac OS X?
8
3
Is it possible to grab the command line that was used to invoke a process on Mac OS X?
11
ps ax
shows you the command line of all running processes; you can grep for the pid you want.
@mark4o Or simply ps awux | cat, as ps -w will not limit the number of columns to display when output is not stdout, such as when piped to another command. – jtimberman – 2009-08-22T21:06:00.037
1
Why does this happen every week? "Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html" and "Note that "ps -aux" is distinct from "ps aux". The POSIX and UNIX standards require that "ps -aux" print all processes owned by a user named "x", as well as printing all processes that would be selected by the -a option. If the user named "x" does not exist, this ps may interpret the command as "ps aux" instead and print a warning. This behavior is intended to aid in transitioning old scripts and habits. It is fragile, subject to change, and thus should not be relied upon."
– Hello71 – 2011-07-27T16:47:45.713I don't know, Hello71. I corrected my two-year-old answer for you. – Bkkbrad – 2011-08-18T18:31:12.267
4
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).
2
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!
3The original poster asked for Mac OS X (which out of the box does not have procfs
) – Andre Holzner – 2012-02-29T22:45:24.213
2Or xargs -0 < /proc/PID/cmdline
– Bash – 2012-09-12T23:22:00.547
1if "-o args=" truncates the output, you can try
ps -p <pid> -o command=
– Jose Alban – 2017-08-18T08:44:11.2271
ps --pid $PID -o args=
That's what I use, anyway... – yardena – 2011-07-26T17:52:09.2502The Mac equivalent of that command is:
ps -p <pid> -o args=
– Nate – 2013-05-07T17:00:35.113