I am trying to run a long running task in the background without having to be logged in and have the terminal return a prompt, but when I do this, the task appears to go into the background, but my prompt does not become available unless I hit control + c. I want to run the task and then get my prompt back.
[staging@php-pos-web ~]$ nohup php test.php > test.txt &
[1] 27251
[staging@php-pos-web ~]$ nohup: ignoring input and redirecting stderr to stdout
To run a nohup command in the background, add an & (ampersand) to the end of the command. If the standard error is displayed on the terminal and if the standard output is neither displayed on the terminal, nor sent to the output file specified by the user (the default output file is nohup. out), both the ./nohup.
Run ping command with nohup command. Re-open the terminal and run pgrep command again. You will get the list of the process with process id which is running.
Ending the nohup command with an & makes the command run in the background, even after you exit the shell. To exit the shell in this situation, enter the exit command. nohup ensures that the command does not end when the creating process ends.
nohup catches the hangup signal (see man 7 signal ) while the ampersand doesn't (except the shell is confgured that way or doesn't send SIGHUP at all). Normally, when running a command using & and exiting the shell afterwards, the shell will terminate the sub-command with the hangup signal ( kill -SIGHUP <pid> ).
You should have your prompt available because your command will be sent to the background. It is possible that you are not seeing your prompt because your command is still delivering stderr messages to your console. Try using > test.txt 2>&1 </dev/null &
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With