Linux Startup and process: foreground process and background process __linux

Source: Internet
Author: User

What is the difference between the foreground process and the background process in the operating system? What is the characteristic.

The background program basically does not interact with the user, the priority level is slightly lower
The foreground program interacts with the user, requiring a higher response speed and a slightly higher priority level.

Manually starting a process directly from the background is less expensive, unless the process is time-consuming and users are not in a hurry to need results. Suppose the user wants to start a process that requires a long run of formatted text files. It is wise to start the process from the background in order not to make the entire shell "paralyzed" during the formatting process.

The difference between a Linux background process and a foreground process

The Linux background process is also called Daemon (Daemon), which is a special process running in the background. It is independent of the control terminal and periodically performs a task or waits to handle certain occurrences.

Generally used as a system service, you can submit with crontab, edit or delete the corresponding job.

The Guardian means not to be controlled by the terminal. Most of Linux's servers are implemented with daemon processes. For example, Internet server Inetd,web server httpd and so on. At the same time, the daemon completes many system tasks. For example, the job planning process Crond, the print process LPD, and so on.

The foreground process is the process that the user uses to have the control terminal

shell, process foreground and background run

Several commands related to System tasks: FG, BG, Jobs, &, Ctrl+z

1. & is most often used

This is used at the end of a command, you can put this command in the background to perform

2. Ctrl + Z

You can put a command that is executing in the foreground to the background and pause

3. Jobs

See how many commands are currently running in the background

4. FG

Move commands in the background to the foreground to continue running

If you have more than one command in the background, you can use FG%jobnumber to call out the selected command,%jobnumber is the serial number (not PID) of the command in the background that was checked by the jobs command.

5. BG will suspend an order in the background, become continued execution

If there are multiple commands in the background, you can use the BG%jobnumber will be selected commands,%jobnumber is through the jobs command to check the background is executing the order number (not PID)

1. Jobs listed background information. ([job number] Run status job name)

2. Ctrl+z the task to the backstage, and paused;

3. BG <%int> wakes up background tasks and runs in the background;

4. FG <%int> Post-mission procedures to the front desk;

1. Ctrl+z the task to the background and paused.

When the main process waitpid (pid,&status,wuntraced), the child process

The parent process is awakened when exiting

2. Wake up the background task, run in the background;

Kill (Pid,sigcont);

3. Put the program running in the background to the foreground;

Kill (Pid,sigcont);

Waitpid (pid,&status,wuntraced);

As you can see, background running differs from foreground operation only because the foreground is running waiting for the child process to exit and blocking the parent process operation. While running in the background, you can enter commands in the parent process to continue other operations. Essentially, there is no difference between sending a sigcont signal to a child process.

Configure parameter Options

1–prefix=<path>-Nginx installation path. If not specified, the default is/usr/local/nginx.

--help View Help Documents

Linux Self-starter program

Use self-starting Apache for example:
There are two ways to get Apache to start automatically when the system starts
1.  to increase the command to start Apache in/etc/rc.d/rc.local, for example:/usr/local/  Httpd/bin/apachectl start
2.  Registers Apache as a system service
first copies the Apachectl command to the/ETC/RC.D/INIT.D directory, renamed HTTPD
Use the editor to open the httpd file and add two lines of text under the first line #!/bin/sh the following
# chkconfig: 35 70 30
# description:   apache
Then register the service
CHKCONFIG&NBSP;–ADD&NBSP;HTTPD
All OK, start the service
Service httpd start
The first of the three numbers added in the second row represents the start of Apache at run Level 3 and 5, and the second to third is about priority configuration for start and stop, which is irrelevant.
automatically run programs in Red hat linux
1. Automatically run the program at power-on startup
after Linux loading,  It initializes the hardware and device driver,  then runs the first process init. Init continues the boot process based on the configuration file to start another process. Typically, modifications are placed in &NBSP;/ETC/RC or  /etc/rc.d  or &NBSP;/ETC/RC? The script file in the d  directory allows init to start other programs automatically. For example: Edit  /etc/rc.d/rc.local  file, at the bottom of the file with a line "Xinit" or "startx", you can start directly after the boot into the X-window.

2. Automatically run programs at logon
When a user logs on, bash first automates the global logon script created by the system administrator:/etc/profile. Bash then finds one of the three special files sequentially in the user's home directory:/.bash_profile,/.bash_login,/.profile, but only the one found first.
Therefore, only by adding a command to the above file according to the actual need can you implement certain programs automatically when the user logs on

3. Automatically run programs when you exit logins
When you exit login, Bash automatically executes the personal exit logon script/.bash_logout. For example, by adding the command "Tar-cvzf c.source.tgz *.c" in/.bash_logout, the "tar" command is automatically backed up *.c files each time you exit the login.

4. Automatically run programs on a regular basis
Linux has a daemon called crond, which periodically checks the contents of a set of command files in the/var/spool/cron directory and executes the commands in those files at set times. Users can create, modify, and delete these command files through the crontab command.
For example, the establishment of a document Crondfile, content of "9 hours * happybirthday", running the "crontab cronfile" command, every 23rd 9:00 system automatically executes the "HappyBirthday" program ("*" It means no matter what day of the week it is.
Linux Boot details:

1 The starting mode and execution order of Redhat are:
Load kernel
Executing the INIT program
/etc/rc.d/rc.sysinit # The first script executed by Init
/ETC/RC.D/RC $RUNLEVEL # $RUNLEVEL is the default run mode
/etc/rc.d/rc.local #相应级别服务启动之后, executing the file (you can actually write the command you want to execute into the file)
/sbin/mingetty # Waiting for user login

In Redhat,/etc/rc.d/rc.sysinit primarily does the same initialization work in each of the running modes, including:
Dial in Keymap and system fonts
Start swapping
Set host name
Set NIS domain name
Check (fsck) and Mount file system
Open Quota
Load sound card module
Set the system clock
/ETC/RC.D/RC the running mode (run level, which you can set in the Inittab file) according to its parameters to execute the script in the corresponding directory. Those who start with the kxx are called by the Stop argument, and all start with the sxx as arguments. The order of the calls is performed in XX from small to large. (where xx is a number, indicating the boot order) For example, assuming that the default run mode is 3,/ETC/RC.D/RC, the script under/etc/rc.d/rc3.d/is invoked in the way described above.
It is worth mentioning that the operating modes in Redhat 2, 3, and 5 all have/etc/rc.d/rc.local as initialization scripts
, so the user can add some commands to the file that need to be executed before they log on after other initialization work.
After the init waits for/ETC/RC.D/RC execution (because the action in/etc/inittab/ETC/RC.D/RC is wait), it will be shipped/sbin/mingetty on each virtual terminal, waiting for the user to log on.
At this point, Linux startup is over.
Init run level and instruction
One, what is init:
Init is one of the most indispensable programs in Linux system operations.
  

Related Article

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.