Linux uses the nohup command to keep the program in the background forever

Source: Internet
Author: User
Today, we use SSH to remotely deploy the project. after the project is deployed, we turn off the terminal and open the webpage to find that there is no service. so we log on to the terminal again and use ps-ef | grepbea to view it, no background process is found. The operating system is Redhat5.5, and the J2EE Server is Web... today, we use SSH to remotely deploy the project. after the project is deployed, we turn off the terminal and open the webpage to find that there is no service. so we log on to the terminal again and use ps-ef | grep bea to view it, no background process is found. the operating system is Redhat 5.5 and The J2EE Server is Weblogic.
So I checked a lot of information on the Internet and finally used the following method. I personally prefer the second method because it does not have to force kill the process.
Method 1: In the startWeblogic. sh Directory, run the "nohup./startWebLogic. sh &" command.
[Weblogic @ localhost guest sys] ps-ef | grep bea



 
Execute the following command when you exit.
[Weblogic @ localhost guest sys] kill-9 2312 2170 29379 29413
The following is the original saying:
"After logging on to the remote computer with the user name and password, you can use the Unix command tail-f text file name to monitor remote file changes, for example, to monitor the log output of a Weblogic domain, you only need to enter the command: tail-f nohup. the premise is that the input command is located in the root directory of the domain and the output log information is specified to nohup when Weblogic is started. in the out text file, that is, the nohup startup method described below.
Start Weblogic Server with nohup: nohup. /startWebLogic. sh &, do not use startWebLogic. sh is started directly because if the Weblogic Server is started directly, disabling SSH will also cause the WebLogic server to be shut down, when nohup is enabled, Weblogic is started to the background and the logs generated by Weblogic are sent to nohup. in SSH, you only need to use tail-f nohup. after logging out, you can view the log information output by Weblogic.
Method 2: use the screen command
The screen command can effectively solve the problem of running background services.
Enter the following command in the terminal:
[Weblogic @ localhost ~] Screen
At this time, the server will start a new terminal and press ctrl + a + d to save the session. However, this terminal is different from the previous normal terminal, it is not affiliated with the sshd process group, so that when the local terminal is closed, the server terminal will not be killed. However, one of the disadvantages of the above is that when the session is too many, it is difficult to clearly distinguish, so we need to use the following command
[Weblogic @ localhost ~] Screen-S sessionname
Press ctrl + a + d to save the session
In this way, you can use the following command
[Weblogic @ localhost ~] Screen-ls
Sessionname. tty1.server (Detached)
You can use the following command to restore a session:
[Weblogic @ localhost ~] Screen-r sessionname
Then, exit and type exit to exit the background process.
Appendix [Note: This appendix is copied and does not belong to me ]:
Use nohup to keep the program running in the background forever
In Unix/Linux, for example, if you want a program to run in the background, many of them use & to make the program run automatically at the end of the program. For example, to run mysql in the background:
/Usr/local/mysql/bin/mysqld_safe -- user = mysql &
However, joining many of our programs is not a daemon like mysqld. maybe our program is just a common program. Generally, this program is used and ended, but if the terminal is closed, the program will also be closed. However, in order to be able to run in the background, we can use the nohup command. for example, if we have a test. php that needs to run in the background and want to run it regularly in the background, we can use the nohup command:
Nohup/root/test. php &
Tip:
[~] $ Appending output to nohup. out
Well, it proves that the program runs successfully. at the same time, it puts the output information of the program running in the nohup. out file of the current directory.
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 & (symbol indicating "and") 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 values:
126 you can find 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 of the Command 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 ).
The 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 preceding example, the output is redirected to the myout. file.
Use jobs to view tasks.
Disable using fg % n.
Two other ftp tools, ncftpget and ncftpput, can be used to upload and download files in the background through ftp, so that I can use these commands to upload and download files in the background.

From linuxOOstudy's column

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.