Nohup command detailed

  

Use nohup to make the program run in the background forever

Under Unix/Linux, for example, if you want a program to run in the background, many use & at the end of the program to let the program run automatically. For example, we want to run mysql in the background:

/usr/local/mysql/bin/mysqld_safe --user=mysql & But adding a lot of our programs does not make a daemon like mysqld, maybe our program It's just a normal program. Generally, this program ends with & but if the terminal is closed, the program will be closed. But in order to be able to run in the background, then we can use the nohup command, for example, we have a test.php that needs to run in the background, and we want to run regularly in the background, then use nohup:

nohup /root/Test.php & Tip:

[~]$ appending output to nohup.out

Well, prove that the operation is successful, and put the output information of the program to the current directory nohup.out Go in the file.

Attached: nohup command reference

nohup command

Purpose: Run the command without hanging up.

Syntax: nohup Command [ Arg ... ] [ & ]

Description: The nohup command runs the command specified by the Command parameter and any associated Arg parameters, ignoring all hangups (SIGHUP )signal. Run the program in the background with the nohup command after logging out. To run the nohup command in the background, add & (symbols for “and”) to the end of the command.

Regardless of whether the output of the nohup command is redirected to the terminal, the output is appended to the nohup.out file in the current directory. If the current directory's nohup.out file is not writable, the output is redirected to the $HOME/nohup.out file. If no files can be created or opened for appending, the command specified by the Command parameter is not callable. If the standard error is a terminal, then all outputs that write the specified command to the standard error are redirected as standard output to the same file descriptor.

Exit Status: This command returns the following exit values:

126 You can find but not call the command specified by the Command parameter.

127 The nohup command has an error or cannot find the command specified by the Command parameter.

Otherwise, the exit status of the nohup command is the exit status of the command specified by the Command parameter.

nohup command and its output file

nohup command: If you are running a process and you feel that the process will not end when you log out of the account, you can use the nohup command. This command can continue to run the corresponding process after you log out of the account/close the terminal. Nohup means no hhang up.

The general form of the command is: nohup command &

Submitting a job using the nohup command

If you submit a job using the nohup command, by default the job All output is redirected to a file called nohup.out unless an output file is specified:

nohup command > myout.file 2>&1 & In the above example, The output is redirected to the myout.file file.

Use jobs to view tasks.

Close with fg %n.

There are two other commonly used ftp tools ncftpget and ncftpput, which can be used to upload and download ftp in the background, so I can use these commands to upload and download files in the background.

Copyright © Windows knowledge All Rights Reserved