Today a friend went to a good foreign company to interview the Linux development position, the interviewer has a following topic:Give the following C program, using GCC to compile under Linux:
1234567891011121314
#include "stdio.h" # Include "Sys/types.h" #include "unistd.h" int main () { NBSP;NBSP;NBSP;NBSP; pid_t pid1; NBSP;NBSP;NBSP;NBSP; pid_t Pid2; NBSP;NBSP;NBSP;NBSP; pid1 = fork (); NBSP;NBSP;NBSP;NBSP; pid2 =
When the thread calls fork, a copy of the entire process address space is created for the child process. The child processes inherit the state of all mutexes, read-write locks, and condition variables from the parent process by inheriting copies of the entire address space. If the parent process contains more than one thread, the child process will need to clear the state of the lock if it is not immediately called Exec, after the
Transferred from: http://blog.csdn.net/koches/article/details/7787468A wonderful thing about a fork call is that it is called only once, but it can return two times, and it may have three different return values:1) In the parent process, fork returns the process ID of the newly created child process;2) in the sub-process, fork returns 0;3) If an error occurs,
Create a new process: fork Function
1.1.1. What is the fork function?# Include # Include
Pid_t fork (void );The 'fork () 'function is used to create a new process from an existing process. The new process is called a sub-process, and the original process is called a parent process. You can check the return value of th
The following system calls are required for process creation under the Unix/linux system: fork/execFork () copies a process into two processes: parent (old PID), child (new PID)EXEC () uses a new program to rewrite the current process: PID has not changedThe next step is to learn the two system calls:When we fork () Create an inherited child process, the following things happen: copy all the variables and m
Reprinted from:
http://blog.csdn.net/yi_zz/article/details/7396987
When I was in class, because of various reasons, the class teacher said he always do not love to listen, now to burn, just know the importance of these basic knowledge, now think, also not so difficult. To understand these underlying concepts, and then test the exam is a few very simple concepts and calculations, here I will explain the tree and the two-fork tree of some testing cente
);//return Value: The parent process ID of the calling process5uid_t Getuid (void);//return value: The actual user ID of the calling process6uid_t Geteuid (void);//return value: The valid user ID of the calling process7gid_t Getgid (void);//return value: The actual group ID of the calling process8gid_t Getegid (void);//return value: The valid group ID of the calling processThe above 6 functions, if executed successfully, return the corresponding ID value, or 1 if it fails. In addition to the pro
function, the source process is completely substituted by the new program, and the new program executes from its main function. Because calling exec does not create a new process, the process ID before and after does not change. exec just replace the body, data, heap, and stack segments of the current process with another new program . In particular, file descriptors that have been opened in the original process will remain open in the new process unless their "Close flag on Execution" (Close o
The C language under Linux can use fork () to establish a child process.The fork function returns two values, and returns 0 for the child process; The parent process, which returns the child process ID. So withif (fork () ==0){The code snippet executed by the child process;}Else{The code snippet executed by the parent process;}Two. The
A new process created by Fork is called a subprocess (child process). The function is called once, but returns two times. The difference of two returnsis that the return value of the child process is 0, and the return value of the parent process is the process ID of the new process (child process). The reason for returning the child process ID to the parent process is that because there can be more than one child process for a process, there is no fun
The so-called process control is that the system uses a number of specific functions of the program to create processes, undo processes, and complete the process of transitions between various states,so as to achieve multi-process efficient concurrent execution and coordination of resource sharing purposes. Process Control is an important task of process management and processor management. 1. Fork () Create processIn Linux systems, the first process
/*1. Node: node contains a data element and several points to its subtree branch2. Degrees node: The number of nodes has become a subtree of nodes3. Leaf node: node 0 is called Leaf Junction.4. Branch nodes: nodes with degrees not 0 are called branch nodes5. The degree of the tree: the maximum value of the degree of all nodes in the tree6. Two fork tree: is a set of N (n>=0) finite nodes. The n=0 tree is called an empty binary tree. The N=1 tree has o
12 storage structure of a fork tree 1.1 sequential storage structureThe sequential storage structure of binary tree is to store the nodes in the binary tree with one-dimensional array, and the storage location of the nodes, and also the subscript of the array to embody the logical relationship between the nodes, such as the relationship between parents and children.Storage of a complete binary tree:Generic binary Tree storage: Although the sequence nu
#include A new process created by Fork is called a subprocess (child process). The function is called once, but returns two times. The difference of two returns is that the return value of the child process is 0, and the return value of the parent process is the process ID of the new process (child process). The reason for returning the child process ID to the parent process is that because there are more than one child process in a process, there is
Three different methods (fork, exec, source) fork (/directory/script. sh) fork is the most common, that is, directly using/directory/script in the script. sh to call the script. sh script. run a sub-sh... three different methods (fork, exec, source) fork (/directory/script.
1. Fork system call
Contains the header file Function: create a sub-processFunction prototypePid_t fork (void );Parameter: No parameter.Return Value:If a child process is successfully created, the child process ID is returned for the parent process.If a child process is successfully created, the return value is 0 for the child process.-1 indicates creation failed.
(1) The child process obtained by using th
We all know that a good way to create sub-processes in Linux is to call the fork function, but many beginners may have difficulty understanding the fork. Let's take an example to see how to use fork. When using fork, remember that fork is"
Forks . I remember that when I was
==============Thread Basics: Multitasking (--fork/join) framework (Basic use)3. Use Fork/join to solve practical problemsIn the previous article explaining the basic use of the Fork/join framework, the example given is to use the Fork/join framework to complete the 1-1000 integer summation. This example would be fine i
First, fork introductory knowledgea process that includes code, data, and resources assigned to the process. The fork () function creates a process that is almost exactly the same as the original process through system calls, where two processes can do exactly the same thing, but two processes can do different things if the initial parameters or incoming variables are different.Once a process calls the
0. order 1. basic Content 1) Process Composition: 2) after the fork function is called, the system does the following work: 2. function details 1) function prototype 2) function 3) description 3. summary:
0. OrderThe fork function is a function used to create a process in Linux. It is also the only function used to create a process. Therefore, I learned the basics of
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.