Last active
August 28, 2020 09:40
-
-
Save mgreenly/7a102c0bb8427b30d00dac7b0f89d440 to your computer and use it in GitHub Desktop.
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
Process.setproctitle("foo-parent") | |
ppid = Process.pid | |
fork do | |
exit if fork # You can only setsid if you're in a child process so first we fork | |
Process.setsid # and exit the parent then setsid in the child. Now that we have a | |
exit if fork # new session create a child process in it and exit the parent again. | |
Dir.chdir("/") # Finally, change directory to one that can't be deleted or moved. | |
Process.setproctitle("foo-child") | |
while true | |
puts 'child' | |
sleep 0.5 | |
end | |
end | |
while true | |
puts 'parent' | |
sleep 0.5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment