Resume a process via a PID number
jobs
will only list the jobs that are associated with the shell that the jobs
command is run in, and similarly fg
and bg
only work with processes on the same process tree as the current shell. In the context of this question, the job you want to attach to was started with /etc/rc.local
, so that shell is not the current one you are in.
You could start the process from /etc/rc.local
with the screen
command (https://help.ubuntu.com/community/Screen) - this will start it up attached to a pseudo terminal, then you can later use screen
again to attach to that terminal and type characters at the running program.
Install screen
using apt-get
, then type man screen
to see all the options. I'm not sure exactly what you should put in rc.local
and don't have time right now to experiment, but may update this answer later.
You can resume a process via a PID number from any shell by using the kill command.
kill -CONT <pid>
Don't forget the -CONT part or you will kill your process.
P.S. David Purdue is correct that fg
and bg
only work with processes on the same process tree. His solution seems to be a better fit your needs.
However because the title is "Resume a process via a PID number" I figured that others who do need this might want to find it.
Borrowed from Vijay
Use the jobs
command to find the list of background processes that are started by you.
for eg: there is script which simply sleeps for 10 secs in 5 iterations.I ran it 4 times in the background.
>jobs
[1] + Running ./temp.sh
[2] - Running ./temp.sh
[3] Running ./temp.sh
[4] Running ./temp.sh
fg
is the command to bring it back to the foreground as shown below.
>fg 1
[CTRL -c]
as seen above i have ended the process and it no longer exists.
now if i again run jobs
>jobs
[2] + Running ./temp.sh
[3] Running ./temp.sh
[4] - Running ./temp.sh
>
Also you can check here for more