Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nohup as background task does NOT return prompt

Tags:

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
like image 265
Chris Muench Avatar asked Apr 12 '14 01:04

Chris Muench


People also ask

How do I run a command in the background using nohup?

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.

How do I know if nohup is running?

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.

How do I exit nohup?

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.

What is difference between nohup and &?

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> ).


1 Answers

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 &.

like image 100
Devon Avatar answered Sep 22 '22 16:09

Devon