When i write a shell script like below:

# demo.sh
somework &

Then run it sh demo.sh.Use & will cause the demo.sh exit and make the somework's parrent PID be 1, the init.

Then i exit my terminal, make the session over, why the somework doesn't receive the HUP, and jobs can't show it. So i guess it has been disown.

I write some code in ruby to test it:

# Fork an process then sleep it.
fork do 

Then i run it with ruby demo.rb. With ps shown it parent process is init now.

Then i exit my terminal. It still running.

Why when a process become an orphan will disown it ?



Got my answer from GNU Manual:

To prevent problems, process groups that continue running even after the session leader has terminated are marked as orphaned process groups.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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