Click to See Complete Forum and Search --> : Background jobs


mka
12-29-2000, 05:27 AM
In school I had a Unix account. That account didn't allow us to run background jobs.

How does one control background jobs?

I would like to perhaps run an eggdrop on my computer one day and I don't want it killed automatically.

Or is that (killing background jobs) done with special scripting?

Thanks!

------------------
mka

George W. Bush: "A key to foreign policy is to rely on reliance."

mattmorrow
12-29-2000, 10:39 AM
1) place a job in the background:
a) Mylongjob.sh &
or
b) Mylongjob.sh
Ctrl-Z
bg %1

bg is "background", %1 is like the job number.
%1 might be %2, %3, %4, etc. depending on how many background processes there are.

2) Check your background jobs:
jobs

This returns the job number (%1, %2, etc) and the PID

3) Kill the job:
kill %1
or
kill PID # where PID is the PID number

4) Bring a background job to the foreground:
fg %1
or
fg PID

HTH!

mtf8
12-29-2000, 12:09 PM
I've noticed some strange behavior regarding these background jobs. From a bash shell I can start a background job (#xchat &), but if I close the original Eterm window that launched the background job, the job (xchat in the example) will terminate.

Wierd eh?

Energon
12-29-2000, 01:17 PM
Originally posted by mtf8:
I've noticed some strange behavior regarding these background jobs. From a bash shell I can start a background job (#xchat &), but if I close the original Eterm window that launched the background job, the job (xchat in the example) will terminate.

Wierd eh?



You've killed the shell process that's running the job... no way for the program to run if the shell's dead...

knute
12-29-2000, 04:16 PM
And yes there are ways to limit/prevent the background processes in linux as well...
(Pam, security settings, etc).... http://www.linuxnewbie.org/ubb/smile.gif

mdwatts
12-29-2000, 05:17 PM
There is a way to keep the process running even if you close the terminal session or logoff.

Cannot remember how, but I either read it here somewhere or was in the HOW-TO's.

If I come across it, I will post the answer.

Actually it might be the NOHUP command.

mdwatts
12-31-2000, 03:56 AM
Probably not interested anymore since you haven't responded to any of the suggestions, but if anyone would like to know.

nohup /path/to/command/runthis &

This will run the command in the background and continue to run the process even if the user logs out.

mka
12-31-2000, 04:11 AM
Still interested!

Just haven't gottten around to using the info yet!

Thanks!

------------------
mka

George W. Bush: "A key to foreign policy is to rely on reliance."

mdwatts
12-31-2000, 05:28 AM
Your welcome...

henryst
12-31-2000, 06:07 AM
Seriously, thanks. That is really cool!

Strike
12-31-2000, 07:19 AM
Random bit of Linux knowledge to help you remember that command. The HUP signal (SIGHUP) is short for "Hang UP". It's a way of ending a process (and sometimes restarting it). But, running nohup ensures that that signal is ignored (or is it handled?), making it immune to SIGHUP signals. Well, those signals are what get sent to processes that are running in a terminal window when the terminal window closes (or likewise for other shell sessions).

mdwatts
12-31-2000, 07:58 AM
We use nohup when starting our TSM Clients (Tivoli Storage Management) on all our AIX servers. Have to be able to logoff without stopping the process. Remember to use '&' at the end of the command for the process to run in the background.

Best of both worlds. AIX (IBM's Unix) helps with Linux and my Linux experience helps with AIX.

If anyone uses AIX and would like to display the AIX/CDE (Common Desktop Enviroment) on your Linux desktop, ensure the X package 'Xnest' is installed and from a Xterm issue 'Xnest :1 -broadcast xxx.xxx.xxx.xxx &' where xxx.xxx.xxx.xxx is the ip address of the AIX server or Control Workstation. Works the same as eXceed, but without the cost.