Linux background run and boot launch "one" __linux

Source: Internet
Author: User
Tags jboss

This article will explain how Linux runs a program in the background, as well as the boot mechanism and if the setting starts up, it also provides some references.

First of all, how to run the background, the exact gesture terminal closed after the end of the process started in the terminal.

We all know that Linux programs are in the terminal unit. If a program is started in a terminal, the corresponding program terminates when the terminal is closed.

Why is that so? Because the process that a terminal starts in Linux is its subprocess, when the terminal shuts down, Linux will receive the signal of hung up (the meaning of hanging the telephone), then the child process of the corresponding terminal is closed, then there is no then ...

So there are two ways to make a process not end:

1. Let Linux ignore the terminal hung up signal, do not close the process;

2. Let this process become a terminal non child process.

The first implementation scenario is the Nohup command.

For example, to start JBoss, you can nohup./run.sh &. This is OK, and the end of the "&" symbol indicates that the background starts JBoss, which does not affect continuing to run other commands.

But there is a problem, nohup command can let Linux "pass" this process, but Nohup will also redirect the process console output under Nohup.txt (the default is this file), of course, can be redirected to other files, but the output is always there.

If JBoss runs for a long time, and if there is a lot of console output, the Nohup.txt file will become very large.

Usually the log in the project is output to a specific log file or output to the database, which means that the console output for the program is not significant, then can discard these output. The answer is yes.

Here's a look at Linux redirection (note that Linux is redirected, not for nohup).

0, 1, and 2 represent standard input, standard output, and standard error information output, which can be used to specify standard inputs or outputs that require redirection.

In general use, the default is the standard output, both 1. When we need special use, we can use other labels. For example, the error message for a program is exported to the log file:./program 2>log. The standard output is still on the screen, but the error message is exported to the log file.

In addition, redirects between 0,1,2 can also be implemented. 2>&1: redirect error information to standard output.

Linux also has a special file/dev/null, it is like a bottomless pit, all redirected to its information will disappear without a trace.

Combined with nohup, we can do this nohup./run.sh >/dev/null &

This is the simplest way to ensure that the program can always perform in the background, and that it will not produce too large nohup.txt files.

The second way is to take advantage of a Linux mechanism that allows programs to execute in Subshell, simply by enclosing the commands in parentheses ().

Ps-ef | grep test

You can see that the run.sh parent process is 1, not the current terminal, so you can ignore the hung up signal.

Of course Linux can also dynamically let the program run in the background or not be hung up signal shutdown, such as disown command, SetID command and so on.

can refer to this article: http://www.cnblogs.com/xianghang123/archive/2011/08/02/2125511.html

The next article continues to explain the Linux boot mechanism.

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.