LINUX nohup Command Input and Output

Source: Internet
Author: User
Tags exit in

You may encounter a nohup command problem. Here we will introduce the solution to the nohup command problem. Linux itself is the core part of the operating system, that is, the kernel of the operating system. The kernel is the most basic program for completing operations. It is responsible for the startup and termination of other programs, such as text editor programs, memory application processing, hard disk access, and network connection management. In Unix/Linux, you generally want to run a program in the background. Many of them use & at the end of the program to run the program automatically.

For example, we want to run mysql in the background:/usr/local/mysql/bin/mysqld_safe-user = mysql & but many of our programs do not support daemon like mysqld, maybe our program is just a common program. Generally, even if this program is used and ended, if the terminal is closed, the program will be closed. In order to be able to run in the background, we need to use the nohup command. For example, if we have a start. sh that needs to run in the background and want to run it all the time in the background, we should use nohup:

Nohup/root/start. sh &

After you press enter in shell, the following message is displayed:
[~] $ Appending output to nohup. out the standard output of the original program is automatically changed to the nohup. out file in the current directory, which plays the role of log. But sometimes there is a problem at this step. When the terminal is closed, the process will be automatically closed. Check nohup. out to see that the service will be automatically closed when the terminal is closed. After consulting with the red-flag Linux engineer, he could not solve the problem. After executing the command on my terminal, the process he started was still running after the terminal was closed.

During the second demonstration to me, I found that I had a different detail with him when operating the terminal: when the shell prompts that nohup is successful, you also need to press any key on the terminal to return to the shell input command window, and then enter exit in the shell to exit the terminal; however, I click the close program button to close the terminal every time the nohup operation is successful .. Therefore, the session corresponding to the command will be disconnected at this time, and the process corresponding to nohup will be notified and shutdown will be required together. I did not notice the details, so I recorded them here.

Appendix: 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 relevant Arg parameter, ignoring all SIGHUP signals. After logging out, run the nohup command to run the program in the background. To run the nohup command in the background, add the "and" symbol to the end of the command.

Whether or not the output of the nohup command is redirected to the terminal, the output will be appended to the nohup. out file in the current directory. If the nohup. out file in the current directory cannot be written, the output will be redirected to the $ HOME/nohup. out file. If no file can be created or opened for append, the Command specified by the Command Parameter cannot be called. If a standard error is a terminal, write the specified command to all outputs of the standard error as the standard output and redirect it to the same file descriptor.

Exit status: This Command returns the following export value: 126 can be searched but cannot 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 specified by the Command parameter.

Nohup command and output file

Nohup command: If you are running a process and you think the process will not end when you exit the account, you can use the nohup command. This command can continue running the corresponding process after you exit the account/Close the terminal. Nohup means not to suspend (n ohang up ).

This command is generally in the form of: nohup command & use the nohup command to submit a job
If you use the nohup command to submit a job, all the output of the job is redirected to a file named nohup. out by default, unless the output file is specified separately:
Nohup command> myout. file 2> & 1 & in the above example, the output is redirected to the myout. file. Use jobs to view tasks. Disable using fg % n.

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

  1. Command Daquan: Linux File Creation command
  2. Command Daquan: Linux File Creation command
  3. Linux chmod commands
  4. Differences between soft and hard links in Linux
  5. Introduction to inode and soft-hardware links from Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.