Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How to get parent pid from a given children pid?

I know I can mannully check it under /proc, I am wonder if there is a smart/better way to achieve this in Ubuntu. Note the parent may or may not be killed.

Thanks

share|improve this question

1 Answer 1

How to get a parent PID (PPID) from a child's process ID (PID) using the command-line

Use ps -o ppid=

  • e.g. ps -o ppid= 2072 returns 2061, which you can easily use in a script etc.
  • Fuller explanation: ps -f 2072 returns
    UID        PID  PPID  C STIME TTY      STAT   TIME CMD
    izx       2072  2061  0 07:16 ?        S      0:00 /usr/lib/pulseaudio/pulse/gconf-helper
    
  • The pstree relation is: pstree -s -p 2072:
    init(1)───pulseaudio(2061)───gconf-helper(2072)
    
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.