Home » Questions » Computers [ Ask a new question ]

How to get command line of UNIX process?

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?

Asked by: Guest | Views: 130
Total answers/comments: 2
bert [Entry]

ps ax shows you the command line of all running processes; you can grep for the pid you want.
bert [Entry]

"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!"