Process name from its pid in linux

TheForbidden picture TheForbidden · Mar 21, 2013 · Viewed 51k times · Source

How to get a process name from his pid ? For example I execute cat file1.txt, but I want to figure out that cat command and its arguments since its pid in the system. Is there a struct to determine it or something similar? Any idea?

Answer

Anubhab picture Anubhab · Mar 21, 2013

There is not any general way to do this unix.
Each OS has different ways to handle it and some are very hard. You mention Linux though. With Linux, the info is in the /proc filesystem.
To get the command line for process id 9999, read the file /proc/9999/cmdline.