Skip to content

Instantly share code, notes, and snippets.

@utkarshkukreti
Created November 5, 2012 13:22
Show Gist options
  • Save utkarshkukreti/4017154 to your computer and use it in GitHub Desktop.
Save utkarshkukreti/4017154 to your computer and use it in GitHub Desktop.
Print list of child processes of a process using Ruby
➜ pry
[1] pry(main)> pid = Process.pid
=> 14683
[2] pry(main)> 5.times { fork { sleep 60 } }
=> 5
[3] pry(main)> puts `ps o pid,ppid= | grep #{pid}$`.split("\n").map{|line| line.split.first}
14707
14708
14709
14710
14711
14712
=> nil
# Note: this includes the `grep` process, so prints 1 extra pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment