3

I am learning for the Red Hat certification. In the book it is stated that since RHEL 7 (so also Centos latest version) that you dont need to use nohup anymore if you launch a process in the background, if you kill the parent shell the started process wont be killed anymore.

I tried to test this and saw two behaviours. If I ran

sleep 3600 &

then it is as said in the book and I see the process running even if I kill the parent shell.

If I run (example from the book)

dd if=/dev/zero of=/dev/null &

and I kill the parent shell then I dont see anymore the process.

Can anyone tell why is this ?

  • 1
    I'm not convinced that SF is mend to be your personal teaching assistant. – user9517 supports GoFundMonica Oct 23 '16 at 20:24
  • 2
    luckily we dont care of what you are convinced or not. I saw a behavior that is curious and would like to have an explanation since I could not find one. If you can answer please answer otherwise see of your business. – dragosb Oct 23 '16 at 20:32
  • I've tried the sleep command and the process dies when the shell is exited. Would you please include the reference (book title and the exact quote where it says so)? I passed my RHCSA recently but I don't recall reading about this new behavior (might be just me not remembering). – dr01 Oct 24 '16 at 11:03
  • The book is the Red Hat Certification Guide by Sander van Vugt. In chapter nine there is a note stating this: "In earlier versions of the bash shell, background processes were also killed when the shell they were started from was terminated. To prevent that, the process could be started with the nohup command in front of it. Using nohup for this purpose is no longer needed in RHEL 7." – dragosb Oct 24 '16 at 21:50
  • Can you show all commands and their outputs. How did you run parent bash shell? How did you look for dd process? What was output of dd command if you run it without symbol & and stop it by Ctrl+C. – Mikhail Khirgiy Oct 25 '16 at 17:18
0

I just repeated your examples on CentOS 7, and in both cases, the processes continued to run after the parent shell was killed. Here's what I did:

Shell 1

$ sleep 3600 &
$ exit

Shell 2

$ ps auxw | grep sleep
www      22268  0.0  0.0 107896   608 ?        S    10:52   0:00 sleep 3600

Shell 3

$ dd if=/dev/zero of=/dev/null &
$ exit

Shell 1

$ ps auxw | grep dd
www      22294  101  0.0 107940   604 ?        R    10:52   0:13 dd if=/dev/zero of=/dev/null

This is pretty nifty behavior that I wasn't aware of in RHEL 7.

For years I've been using screen to run long-lived processes in the background. I probably will continue to use it, because it's nice to be able to reconnect to the output of the process to look for any progress messages it might generate.

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.