Created
November 5, 2012 13:22
-
-
Save utkarshkukreti/4017154 to your computer and use it in GitHub Desktop.
Print list of child processes of a process using Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ 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