foreground process and background process

Source: Internet
Author: User
Tags printf

1. & is most often used
This is used at the end of a command, you can put this command in the background to execute
2. Ctrl + Z
You can put a command that is executing in the foreground in 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 there are multiple commands in the background, you can use FG%jobnumber to bring up the selected command,%jobnumber is the ordinal (not PID) of the command being executed in the background through the jobs command.

5. BG will suspend a command in the background and change to continue execution

If there are multiple commands in the background, you can use BG%jobnumber to bring up the selected command,%jobnumber is the ordinal (not PID) of the command being executed in the background through the jobs command.
1. Jobs lists background job information. ([job number] Run status job name)
2. Ctrl + Z put the task back in the background and pause;

3. BG <%int> Wake up background tasks and run in the background;
4. FG <%int> put the post-mission procedures in the foreground;


1. Ctrl + Z put the task back in the background and pause.
Master process Waitpid (pid,&status,wuntraced), child process
When exiting, the parent process is awakened

2. Wake the background task and run it in the background;
Kill (Pid,sigcont);

3. Put the background running program to the foreground;
Kill (Pid,sigcont);
Waitpid (pid,&status,wuntraced);

void FG (char *p)
{
int pid=0;
if (p!=null)
{
Pid=atol (P);
Kill (Pid,sigstop);
Kill (Pid,sigcont);
Waitpid (Pid,null,null);
pid_jobs[jobs_num--]=0;
}
Else
printf ("Error \ n");
return 0;
}

void BG (char *p)
{
int pid=0;
if (p!=null)
{
Pid=atol (P);
Kill (Pid,sigcont);
pid_jobs[jobs_num--]=0;
}
Else
printf ("Error \ n");
return 0;
}
Visible, the difference between running in the background and the foreground is that the foreground is running to wait for the child process to exit and block the parent process action. While the background is running, you can continue other operations by entering commands in the parent process. Essentially, there is no difference between sending a sigcont signal to a child process.

Http://blog.chinaunix.net/u3/94039/showart_1893558.html

---------------------------

1. Explain the difference between the foreground operation and the background operation.

A: The foreground program and the user directly dialogue, background procedures to provide support for the foreground program, in general, to provide the necessary resources for the foreground program. The background program can either direct the conversation with the foreground program or use intermediate programs as a medium. Programs that the user is working on are referred to as the foreground program, and the program that the user does not operate but is also running (such as system services) is called a daemon.

When the command interpreter creates a background process, it sends out this process command,

And before receiving other commands, don't wait for the process to end.

For example:

$DDD &

And the front desk waits until the end of the process.

For example:

$ddd

Ctrl-c will end DDD.

Foreground program and Terminal Association, background program is not controlled by the terminal.

Broadly speaking, the foreground program/daemon is not a very clear concept. If the C/s structure, usually the client's program as a foreground program, and the server-side program as a background program. Today's operating systems are multi-tasking operating systems that can execute multiple programs at the same time. The foreground program is the program you are currently using, and the daemon is the program you have opened that is not used later but is still running.

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.