LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-27-2007, 10:18 AM   #1
Ricky
Member
 
Registered: Sep 2003
Posts: 34

Rep: Reputation: 15
Urgent : Regarding sending a current running process in background


Hi,

I had started a process which was supposed to be of few minute but due to some reason I hv to run it for 2-3 days without stopping it. I am accessing it using SSH, as I was not aware that It has to run from long.. I did not use "SCREEN" utility or "NOHUP" but now I need it to be running in background.

Since its already running, I can't use Screen and nohup and can't restart it as it will be waste of many hours already used.

so wht I find solution is using
CTRL + Z and then send it to background using
bg 1

but I guess when I will close that SSH window then It will stop that background JOB.

I m running a scrip on large database, if it stops then has to start all over. So without stopping it want to send to background so that I can turnoff my computer here or if some problem in conection then wont' stop that process..

Its realy urgent for me!
 
Old 11-27-2007, 10:59 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Quote:
Originally Posted by Ricky View Post
Hi,

I had started a process which was supposed to be of few minute but due to some reason I hv to run it for 2-3 days without stopping it. I am accessing it using SSH, as I was not aware that It has to run from long.. I did not use "SCREEN" utility or "NOHUP" but now I need it to be running in background.

Since its already running, I can't use Screen and nohup and can't restart it as it will be waste of many hours already used.

so wht I find solution is using
CTRL + Z and then send it to background using
bg 1

but I guess when I will close that SSH window then It will stop that background JOB.
Probably, although that is not certain. When happens is that the process will receive the signal SIGHUP (hang up). Most programs do the default action with this signal - to abort the program - but if the programmer chose to intercept the signal and do something else with it (or ignore it) the program may not quit.

Having said all that, it is probably prudent to assume that SIGHUP will cause the program to terminate.

[QUOTE=Ricky;2972243]I m running a scrip on large database, if it stops then has to start all over. So without stopping it want to send to background so that I can turnoff my computer here or if some problem in conection then wont' stop that process..

Quote:
Originally Posted by Ricky View Post
Its realy urgent for me!
I don't think that helps get a question answered any more quickly. People will only answer if they can, and a question is interesting.

In any case, assuming you are using bash as your interactive shell on the remote host, you can use the disown builtin.
 
Old 11-27-2007, 12:17 PM   #3
Ricky
Member
 
Registered: Sep 2003
Posts: 34

Original Poster
Rep: Reputation: 15
HI methew.. dont' mind about my "urgency" word ..
so you mean using ctl+z said might be risky as it may cause program to terminate... hmm..

So how I use disown ....
I am running process with PID 8769 in other terminal, then I logged into other terminal, typed
Code:
disown 8769
Shall it work this way and wont' stop execution of that process ?
 
Old 11-27-2007, 01:06 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Quote:
Originally Posted by Ricky View Post
HI methew.. dont' mind about my "urgency" word ..
so you mean using ctl+z said might be risky as it may cause program to terminate... hmm..
No, I mean when you close the connection... that is when SIGHUP is sent to all jobs running from that shell (i.e. backgrounded processes).

Quote:
Originally Posted by Ricky View Post
So how I use disown ....
I am running process with PID 8769 in other terminal, then I logged into other terminal, typed
Code:
disown 8769
Shall it work this way and wont' stop execution of that process ?
Usage information can be found in the bash manual page. Essentially you need to specify the job spec which you wish to disown. You can see a list of background job ids by running "jobs".

If you are uncertain, do a test with another process first to verify you have the proper syntax.
 
Old 11-27-2007, 01:12 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
You can also unset the huponexit shopt. To see the current setting of huponexit, do this:
Code:
shopt huponexit
If the setting is "on", it means SIGHUP will be sent to the backgrounded processes when the shell terminates. You can turn it off like this:
Code:
shopt -u huponexit
Note the huponexit setting only applies to login shells. This probably does apply to your ssh session.
 
Old 11-27-2007, 03:07 PM   #6
Ricky
Member
 
Registered: Sep 2003
Posts: 34

Original Poster
Rep: Reputation: 15
nevermind.. I had to restart that proces.. now I am running it under screen .. doing fine !

though disown <PID> is correct syntax.. today wholeday I was playing with similar stuff to understand their behaviour !
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
running process in background forever danran Linux - General 2 11-19-2006 10:44 AM
Running kismet as a background process coolnicklas Linux - Software 2 01-04-2006 04:33 PM
background running process elbriga Programming 2 09-21-2004 07:08 PM
starting a background process running tcpdump on boot butthead Linux - Networking 1 10-15-2003 07:34 PM
sending process to background Robert0380 Linux - General 5 12-31-2002 04:33 PM


All times are GMT -5. The time now is 08:49 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration