Run a command in background and exit

2019-09-19 11:20发布

问题:

I want to run a command silently via ssh and exit the shell, but the program should continue running. I tried screen and nohup, but apparently with those it executes 3 processes instead of 1:

user:/bin/bash ./[script]
root: sudo [commandInTheScript]
root: [commandInTheScript]

What am I doing wrong?

P.S.: The thing is that I want to run this command with the Workflow app (iOS), but the app waits until the command is finished, so it freezes 'forever'

回答1:

To run your process back ground, at end of the command you have to use &. In your case, you have to run without session since you are planning to exit from ssh after execute the command, so you need nohup

nohup <command> &


回答2:

nohup < command > &

This makes your command runs on background and shows its PID



回答3:

How did you use nohup?

Eg.
nohup ruby server.rb &
Ampersand (&) is necessary to let command run in the background.



标签: linux bash ssh