Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-11-2009, 10:15 PM   #1
LQ Newbie
Registered: Jan 2009
Posts: 20

Rep: Reputation: 1
Need help keeping program alive while killing remote session.

I have a program that I wrote to process data from an oracle database. After a week, it's still pulling the data from oracle! I'd sick the dba on the problem, but the dba job was handed to the C++ developer (me, who is also the system admin).

To run the program I did a remote login to a Windows server and used a putty session to run the program so it wouldn't die with my remote network connection. I didn't know about the command "nohup", and now I need to reboot the server to fix another problem. If it were only running for a day or two, I would just restart the program, but I think it's just a day or two from finishing. No matter how long is left, I still loose a week of compute time if the process dies.

What can I do at this point to keep the program from closing with my putty session? I've tried backgrounding processes, but they still exit with the shell. I need to resolve this quickly. I usually scour Google for an answer in these cases, but I'm getting nowhere.
Old 05-11-2009, 10:27 PM   #2
LQ Newbie
Registered: May 2009
Location: San Antonio, TX
Distribution: Debian
Posts: 15

Rep: Reputation: 1
From :

The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from sending the signal to a particular job, it should be removed from the jobs table with the disown builtin (see SHELL BUILTIN COMMANDS below) or marked to not receive SIGHUP using disown -h.


disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.


So, correct me if I'm wrong (I've not used this before), but sounds like

$ disown -h [pid]

would allow you to quit that shell. I might add a 'echo $?' afterwards, to check it exited properly....
Old 05-12-2009, 09:19 AM   #3
LQ Newbie
Registered: Jan 2009
Posts: 20

Original Poster
Rep: Reputation: 1
Thanks for your help and quick reply! The option jobspec is %1, %2, etc (type "jobs" to list them), and it only seems to be usable on the processes launched by your current bash shell. I have to suspend the process first, so I sent it signals 19 and 18 on the same command line, to keep the downtime to a minimal. I don't think the -h is necessary, but that it delays orphaning the process until the bash shell dies. I don't have free time at the moment to test that though.

Thanks again for your help. I've now disconnected the terminal session and my program is still running. Now I'm just hoping that it doesn't die again before inserting the results into Oracle. It did that the last time it ran as an orphan, but it shouldn't have even been an orphan then.
Old 05-12-2009, 10:33 AM   #4
LQ Guru
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
I would use screen then I can easily detach or re-attach to that screen at any time. If I detach the Screen I can end the SSH session without terminating the process running in the screen session.
Old 05-16-2009, 06:49 AM   #5
LQ Newbie
Registered: Jan 2009
Posts: 20

Original Poster
Rep: Reputation: 1
Screen looks rather sweet. It's a little more powerful, feature rich and complex than I need at the moment, so I won't be using it until my development schedule stabilizes enough to devote some time to it. Sadly, that could be December.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
XDMCP - problem keeping sessions alive RedHatCat Linux - Networking 2 06-27-2007 03:05 AM
keeping Xvnc alive after vncviewer dies rcbell Linux - Networking 2 10-12-2006 08:40 PM
closing SSH session without killing the SFTP transfer on the remote machine stevec Linux - Software 2 04-20-2006 05:13 PM
Keeping the connection alive? NonSumPisces Linux - Networking 2 07-08-2004 05:12 PM
Keeping dialup alive kobe Linux - General 3 08-18-2002 01:46 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:12 AM.

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