473,505 Members | 16,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to move job into background after already started

dlite922
1,584 Recognized Expert Top Contributor
i know to use nohup, but what if the user started a very long job and wanted to leave (logoff/logout) without killing the job.

Is there away to move an existing process into the background without restarting it?

This is a situation that came up by a colleague, but curious to know the answer for my future reference.


Thanks guys,


Dan
Jun 29 '10 #1
8 7363
AmberJain
884 Recognized Expert Contributor
You can either nohup or detach a process. You can try using some terminal multiplexer (google tmux or screen) and then detaching the terminal before you logout.
Jun 30 '10 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
Also, if you are running a process from the command line and the command line is tied up by the process and you need it back, you can do a "ctrl-Z" and then type bg.

That will background the process you have running.

Regards,

Jeff
Jun 30 '10 #3
dlite922
1,584 Recognized Expert Top Contributor
@numberwhun
But putting in in background then logging out, still keeps it going?

@Amber, ya, if it was a screen session, I could just detach it. Personally, I always use screen from my gateway host, but if I'm ever on some unusual host that away from our network doesn't have screen, I wouldn't know how to do it.

i'm going to test the bg method and log out, see if the job is still running. Will post back what I find.


Dan
Jun 30 '10 #4
dlite922
1,584 Recognized Expert Top Contributor
Worked!

Thanks @numberwhun


Dan
Jun 30 '10 #5
numberwhun
3,509 Recognized Expert Moderator Specialist
Unfortunately, no, if you log out it probably won't keep going. Its not nohup. But, it does allow you to get our command prompt back.

Also, if you have a program that you know is going to hijack your prompt, then put a & at the end of the line like so:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ./command -opt1 -opt2 &
  3.  
  4.  
That will automatically background the job and give you your prompt back immediately.

Regards,

Jeff
Jul 1 '10 #6
dlite922
1,584 Recognized Expert Top Contributor
that's weird, here's what I did. A php script that in a for loop writes a number to a text file every few seconds. I ran it, Ctrl+Z, then bg and logged off. (when it was at 10)

logged back in about half a minute later and tail -f 'd the file and it was in the 20's or something. It was obviously running when I was offline.

I'll reconfirm and log off for a greater period or log in from another user's and follow the text file.

I'm pretty sure it kept running.


Dan
Jul 1 '10 #7
numberwhun
3,509 Recognized Expert Moderator Specialist
That is weird because ctrl-z is an interrupt.
Jul 1 '10 #8
ashitpro
542 Recognized Expert Contributor
try 'setsid' command...
It will create a process which will run your job and its parent will be init.
I am not sure about behavior after logoff.
But theoretically it should work as we are assigning it to init.
Jul 6 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2129
by: Jerry | last post by:
Hi All How can I produce an output to the browser and let the script continue to work in the background, producing a later screen output? Example: Trigger a database search so that the user...
4
2294
by: Q | last post by:
Hello, I have composed the following simple php file: <html> <head><title> Title. </title></head> <body> <?php header("Location: http://www.something.com/tmp2.php"); ?> </body>
5
2518
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
1
2330
by: sarmin kho | last post by:
Hi Pythoners... I am building a python GUI with wxpython... the python GUI will periodically call a python module written on python 2.2... wxtimer is used to enable the periodic call... it works...
2
1322
by: Stephan Brunner | last post by:
https://beta.microsoft.com tells me that there are NO Enrolled betas Am I in the wrong movie? Where is the official place for VS 2005 / Framework 2.0 Beta 1 testers?
3
4737
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
14
9595
by: Alex K. | last post by:
Hi all I'd like to avoid starting the same c# application twice on the same computer. How do I check if it is already running? Thank you
1
1256
by: adept | last post by:
I try to do it in this way: it is reaction on event OnLoad cpr = Process.GetCurrentProcess(); Process spr = Process.GetProcessesByName(cpr.ProcessName); ...
20
3179
by: Alexey Kulentsov | last post by:
Hi all! Windows XP, Apache 2.2, PHP 5.2.5 as apache module (php5apache2_2.dll) I need to run background process and see output but for current moment all methods runs it as process not as...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.