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.

4
  • pstree seems fine for this. What is the problem you are having? Jul 22, 2015 at 13:48
  • For one thing, when specifying a process, it only shows the processes from it on down (not the ancestors). ptree gives you the whole hierarchy.
    – wsaxton
    Jul 22, 2015 at 13:58
  • Did you miss the -s option in the man page? Jul 22, 2015 at 13:59
  • Our pstree version does not have the -s unfortunately.
    – wsaxton
    Jul 22, 2015 at 14:36

1 Answer 1

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)
5
  • Just a note: The version of pstree coming with CentOS 6 doesn't support the -s option (CentOS 7 has it).
    – Sven
    Jul 22, 2015 at 14:30
  • @Sven Aha, I knew there would be a down side to moving to EL7 rapidly... :) Jul 22, 2015 at 14:33
  • Our pstree version does not have the -s unfortunately.
    – wsaxton
    Jul 22, 2015 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. :) Jul 22, 2015 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, 2015 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .