LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 05-11-2009, 11:15 PM   #1
jbo5112
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, 11:27 PM   #2
jim80net
LQ Newbie
 
Registered: May 2009
Location: San Antonio, TX
Distribution: Debian
Posts: 15

Rep: Reputation: 1
From http://linux.die.net/man/1/bash :

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, 10:19 AM   #3
jbo5112
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, 11:33 AM   #4
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,248
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.

http://www.rackaid.com/resources/lin.../using-screen/

http://magazine.redhat.com/2007/09/2...to-gnu-screen/
 
Old 05-16-2009, 07:49 AM   #5
jbo5112
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.
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:16 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