make a foreground running process to run background without hang up

I've tried this a long time ago and was successful but could not remember how i did it. Tried ctrl+Z and then used bg %

could not figure what i did after to keep it no hangup -

not sure if used nohup -p pid, can u plz help me out if this can be done.

Any help will be appreciated.

To place a foreground process in the background: suspend the foreground process (with Ctrl-z) then enter the bg command to move the process into the background.

Show the status of all background and suspended jobs: jobs
Bring a job back into the foreground: fg %jobnumber
Bring a job back into the background: bg %jobnumber

Regards

Depends on the shell whether bg jobs will receive a HUP when you log out; I believe with bash they will not.

i'm working on a korn shell, but my script is running on bash mode, will it affect ?

You can run your command with `nohup' - this will cause it to ignore all input and send its stdout (and stderr?) to the file "nohup.out" in your cwd. After you've run your command, you can background it as normal (^Z bg) but it will continue to run after you sever the terminal connection.

Depending on your shell (bash for sure, others maybe) you can also use the "disown" command on a job to disconnect it from the controlling terminal.

When you have already started the job you can use "nohup <pid>" to unattach it from the terminal you are on (this is the reason why processes stop when you log off - they are attached to a terminal and this terminal ceases to exist when you log off) so they won't stop when you log off.

Therefore:

$ job                    # starts the job
$ <CTRL-Z>               # stops the job
$ bg                     # puts the job in background
$ nohup <PID>            # unattaches the backgrounded job from the terminal

I hope this helps.

bakunin

I had never heard of nohup PID and it does not seem to be supported by GNU coreutils nohup, so I guess it's not portable. But if it works for you, good.

Hi.

a useful addition to command nohup for Solaris users, but as era says, not usable (so far) in Linux -- nor aix, nor hp-ux, nor freebsd, etc. ... cheers, drl

Sorry, that was indeed a typo on my behalf. Correct is

$ nohup -p <PID>

in AIX.

bakunin

on AIX UNIX ksh it work use it:
press (ctrl+z ) to stop that job
then run (jobs) it who id of stoped job_id
the for running that job in foreground use(fg %<job_id>)
the for running that job in background use(bg %<job_id>)
and to start it in nohup use (nohup `bg %<job_id>`)

Hi, bakunin.

In the version of aix that I use, I find:

$ jobs
$ version =o
aix 5.1
$ jobs
$ sleep 100 &
[1]     30552
$ nohup -p $!
Sending nohup output to nohup.out.
nohup: -p: A file or directory in the path name does not exist.
$ echo $!
30552

What version of aix are you using? ... cheers, drl

I tried that with AIX 5.3 ML6. Here is a link verifying that:

nohup Command

Still, i have seen in the meantime, while sifting through older documentation, that "-p" is nonstandard. I have never needed it until recently, when i looked it up and found that option - so i took it for granted, unaware that it is not as common as i thought.

bakunin

i face the same problem with the nohup commnad,anyway if you want the nohup to run
successfully dont use the ctrl + Z,just close the telnet window and go out the system
login to the system again and you can see that your program is working
nohup /usr/bin/ksh <xxx>.sh
i try it on tru UNIX V4.0F and it works