LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-20-2010, 11:29 AM   #1
gjagadish
Member
 
Registered: Oct 2005
Location: India
Distribution: Fedora Core
Posts: 88

Rep: Reputation: 15
How to test disown and nohup commands ?


Hi,

I ran a perl script in background with nohup and disown to make sure my script runs even after the parent process is terminated.

Method 1: nohup
> nohup perl run.pl &
[1] 2080

Method 2: disown
> perl run.pl &
[2] 2448
> disown

In either method, the script process doesn't seem to connect to init process, when I checked using pstree command. I thought, the disown or nohup command detaches the process from its parent and attaches it to grand grand parent init process. And it disables SIGHUP signal to my script process.

But the pstree command didn't show me what I expected. It still shows my script process attached to my current terminal process.

I just don't understand the concept behind these two commands (nohup and disown). Is there any way, I can see the list of processes that are run by nohup or disown command ?

Thanks in advance
Jagadish
 
Old 03-20-2010, 02:19 PM   #2
LinuxTutBlog
LQ Newbie
 
Registered: Mar 2010
Location: On the web
Posts: 6

Rep: Reputation: 0
Let's see, you're asking multiple questions. I'll try to answer them all.
  • "the script process doesn't seem to connect to init process, when I checked using pstree command"
    • Neither nohup nor disown will actually move the process in the pstree. Movement will happen when you close the shell.
  • "I just don't understand the concept behind these two commands (nohup and disown)."
    • nohup makes sure a process won't stall if the terminal loses connection somehow (without nohup, a process could stall because nothing reads its output anymore)
    • disown tells the shell to forget that the specified job is a child process of the shell, meaning that the shell won't kill it on exit
  • "Is there any way, I can see the list of processes that are run by nohup or disown command ?"
    • I haven't been able to find an easy way. You could use lsof to check if a process has an unconnected stdin and stdout/stderr directed to nohup.out, which would indicate that it's been started using nohup. For disown, you can compare the output of `ps -o pid= --ppid <pid>` with that of `jobs -l | awk '{ print $1; }'`; pid's occuring in the former and not in the latter are either disowned or not started by the shell itself.
I hope this clears things up a bit. If you still don't understand everything, don't hesitate to ask. I might even write a tutorial about it .
 
Old 03-21-2010, 04:33 AM   #3
gjagadish
Member
 
Registered: Oct 2005
Location: India
Distribution: Fedora Core
Posts: 88

Original Poster
Rep: Reputation: 15
Thank you very much for your explanation. It makes perfect sense
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
commands to test internet connection specialized Linux - Networking 7 11-22-2009 09:55 PM
How to use nohup and disown in a script? jf.argentino Programming 11 10-06-2009 07:02 AM
Nohup and disown usage raghu123 Programming 6 06-10-2009 04:51 AM
disown problem (sh: disown: not found) grayFalcon Linux - Server 2 01-07-2008 06:20 AM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 11:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration