11

I wanted a daemon to start on boot so I added a line to /etc/rc.local that ended in "&" I did that so it would run in the background.

The daemon is loaded and working fine but when the daemon is running you can press keys that do other important things.

When I am finally logged in I wanted to resume process or send it a terminal (tty2) so I can do a couple of things.

I'm new to linux and not sure how to do this.

I do a ps -aux |grep uox to work out which PID it is. But not sure how to resume.

3 Answers 3

9

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.

8

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.

6

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

1
  • only works if you are in the same process that spawned the pid
    – mtyson
    Dec 6, 2019 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .