LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   magic with nohup (http://www.linuxquestions.org/questions/linux-newbie-8/magic-with-nohup-4175436213/)

r_s 11-08-2012 02:52 AM

magic with nohup
 
I have two files file1 and file2. Within file2 I am running a daemon in the background as user user1.
And I am executing this file2 from within file1, running file1 as root. This creates two process one being executed as root and the other as user1. However if add a nohup before the invocation of the daemon in file2, it shows only one process being run as user1.

A little more explanation.

file1
Code:

#!/bin/bash
file2

file2
Code:

#!/bin/bash
sudo -u user1 java daemon &

and now ps aux gives..
Code:

root  file2
user1  java daemon &

however adding a nohup to file2, like
Code:

nohup sudo -u user1 java daemon &
shows just one process running as user1.

chrism01 11-08-2012 04:13 AM

That's because nohup disconnects from the calling process; that's what its supposed to do. Hence, the calling script immediately runs to completion.
You can use a few echo statements to see the difference, or add 'set -xv' thus
Code:

#!/bin/bash
set -xv



All times are GMT -5. The time now is 07:49 AM.