I'm running Slackware 13.37, and I was wondering if there was a way to tell which script executed a command. I tracked the process and its arguments, but I would like to know where the command originated from.
1 Answer
There is no guaranteed generic way to do that apart from walking the process tree (by looking at the commands PPID, then that process's PPID, etc...).
There's a good utility for that though, if you're not trying to script something: pstree. It will give you a "graphical" view of the process hierarchy. Something like:
$ pstree -a
...
├─udevd --daemon
│ ├─udevd --daemon
│ └─udevd --daemon
├─urxvt
│ └─bash
│ └─pstree -ah
└─xdm
├─X :0 vt7 -auth /var/lib/xdm/authdir/authfiles/A:0-g8w3zk
└─xdm
└─awesome
├─chrome
│ ├─chrome
│ └─21*[{chrome}]
└─qmpdclient
└─{qmpdclient}
There are options to show the PIDs, show or hide the command lines, etc...
-
1You can also use
ps -axf. Thefis for forrest, but it looks like a tree. ;-)Keith– Keith2011-05-27 05:25:25 +00:00Commented May 27, 2011 at 5:25
process+monitoringmight provide inspiration.