0

I'm trying to track the usage of a certain command so I want to log its parents (to see what is actually using it)

Solaris has "ptree" which would be pretty easy to parse and log:

# ptree 4198
4198  /usr/bin/perl -S /sample.pl
  4228  /usr/bin/java -server -cp /sample.java

Linux doesn't seem to have an equivalent. I've tried using "pstree" and "ps -auxf" and others without much success.

wsaxton
  • 195
  • 11

1 Answers1

0

pstree seems fine for this.

Consider:

$ pstree -p 3281
nginx(3281)─┬─nginx(3282)
            ├─nginx(3283)
            ├─nginx(3284)
            ├─nginx(3285)
            ├─nginx(3286)
            └─nginx(3287)

And use -s to see parents:

$ pstree -p -s 3287
systemd(1)───nginx(3281)───nginx(3287)
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Just a note: The version of `pstree` coming with CentOS 6 doesn't support the `-s` option (CentOS 7 has it). – Sven Jul 22 '15 at 14:30
  • @Sven Aha, I knew there would be a down side to moving to EL7 rapidly... :) – Michael Hampton Jul 22 '15 at 14:33
  • Our pstree version does not have the -s unfortunately. – wsaxton Jul 22 '15 at 14:35
  • That's bad news. I'll leave this here, though, for others with the same question, and for later when you migrate to a more modern Linux. :) – Michael Hampton Jul 22 '15 at 14:38
  • I'll accept this answer as its the only thing I've found so far, even though it only works for newer versions (it will slowly become even more correct over time!) – wsaxton Jul 26 '15 at 13:20