Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Last active August 28, 2020 09:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgreenly/7a102c0bb8427b30d00dac7b0f89d440 to your computer and use it in GitHub Desktop.
Save mgreenly/7a102c0bb8427b30d00dac7b0f89d440 to your computer and use it in GitHub Desktop.
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