2

Is there a way I can have a continuously running, background process that can be controlled by me (a regular, non-root user)?

All I need to be able to do is start, stop and restart the process. Monitoring by PID and sending SIGHUP or SIGINT for termination is fine. I'm okay with using a complicated bash script, it doesn't have to be something system-wide. Just for me.

I also really need it to not stop when I log off from ssh.

Is there a way I can do this in RHEL 6.4?

1 Answers1

2

screen or tmux

Sure you can start processes and have then run continuously by making use of a terminal multiplexer such as screen or tmux. Processes can continue to persist in a screen or tmux session, and you can connect/disconnect to either (screen or tmux) as needed.

backgrounding

You can run any process you like and then background it and then disconnect it from your current terminal using the command disown.

$ disown -a

Additionally if you just want to start a process up and not have to background it and disown it you can use the command nohup.

$ nohup myexec &

When you exit the shell, myexec will continue to be running.

Example

Start a fake process.

$ sleep 12345 &
[1] 24339
$

Make sure we can see it:

$ pgrep -f "sleep 12345"
24339

But it's still connected to our terminal:

$ jobs
[1]+  Running                 sleep 12345 &

So let's disown it:

$ disown -a
$ jobs
$

See it's still running:

$ pgrep -f "sleep 12345"
24339

Now let's log out, and log back in. See it's still there:

$ pgrep -f "sleep 12345"
24339

You can kill this process any time using standard means:

$ pkill -HUP -f "sleep 12345"
$ pgrep -f "sleep 12345"
$ 

The above will send the signal HUP to a process name matching the pattern "sleep 12345". Double checking shows that it's now gone.

slm
  • 369,824