Running new code in the processThe EXECX series function can run a new program in the current child process. When a process invokes any function in the series, the process's user-space resources are completely replaced by the new program.The difference between these functions: Indicates whether the location of the new program uses a path or a file name, and if the file name searches for the program in the path described by the system's $PATH environment variable.How to use the parameter list or
EXECLP", NULL)
2.6 execle Function
if (fork () = = 0) {
//child process
char * env[] = {"Path=/home/gateman", "User=lei", "status=testing", NULL};
if (Execle ("/usr/bin/env", "env", null,env)
Output:
3. Fork () and EXEC functions are compared with system () functions
See the output of the EXECVP function above. You'll find that the EXEC function is just a system call, and it doesn't
Execl (file, arg0,arg1,...) Execute file with parameter list arg0, arg1, etc.Execv (file, arglist) in addition to using a list of parameter vectors, the other is the same as EXECL ()Execle (file, Arg0,arg1,... env) and execl are the same but provide an environment variable dictionary envExecve (file,arglist, env) except with a list of parameter vectors, the others are the same as execle ()EXECLP (cmd, arg0,
:
# Write to ttys0
Copy code
3. control terminal (/dev/tty)The control terminal is not a device, but a process. For this concept, Chapter 9th of UNIX advanced programming is described in detail.
Ii. logon from Terminal
During Linux boot, The INIT process will be run and/etc/inittab will be executed (this is related to the specific init type. I used the init of busybox, but its essence is the same ):
[Root @ Skynet ~] # Cat/etc/inittab
: Sysinit:/etc/init. d/RCS
: Respawn:/sbin/Getty 9600
the same way. They replace the current process with a new process. That is to say, you can use the exec function to switch the execution of a program from one program to another, after the new program starts, the original program will no longer be executed. The new process is specified by the path or file parameter. Exec functions are more effective than system functions. Exec functions are of the following type:
#include These types of functions can be divided into two categories. The paramete
Exec replacement process impression, exec Replacement Process
Overview
On Process Creation, UNIX/Linux adopts a unique method, which separates Process Creation from loading a new process image (system calls combine these two operations ). The advantage is that there is more room to manage the two operations.
After we create a process, we usually replace the child process with a new process image. This can be done using exec functions. Of course, the exec series functions can also replace the cu
to create a child process, all the opened descriptions in the parent process are shared in the child process. this feature is widely used in network servers, for example, if the parent process returns a socket through the socket function and then calls the fock function to create a word process, the child process can directly operate on the existing socket. Another typical application of fock is to create a sub-process to call the exec function to execute new programs instead of itself.
3. p
description is the parent process. If it is less than 0 (actually-1), the creation process fails.Each process has a unique identifier, PID, which can be obtained using getpid (). The PID returned by the parent process is actually the PID of the child process.As it seems, fork () has no effect after all. In fact, if the fork () after the use of other Linux functions, or very useful. For example, we can communicate through the communication protocol in the parent-child process, and we can accompl
process creation from the loading of a new process image . The advantage is that there is more room to manage the two operations. When we create a process, we usually replace the child process with a new process image, which can be done using the EXEC series function. Of course, the Exec series functions can also replace the current process. exec simply replaces the current process's body segment, data segment, heap segment, and stack segment with a new program on the disk.Function Family Infor
: "Login:" and other prompts, waiting for user input.When the user types the user name, Getty executes The login program, similar to the following: Execle ("Login"). Login can call Getpass () to display password: and read the user's password. and call Getpwnam for password authentication. If successful, the call is similar to execle ("shell"). In this way, the logged-on user has a shell.Third, pseudo-termin
Execl (file, arg0,arg1,...) Execute file with parameter list arg0, arg1, etc.Execv (file, arglist) in addition to using a list of parameter vectors, the other is the same as EXECL ()Execle (file, Arg0,arg1,... env) and execl are the same but provide an environment variable dictionary envExecve (file,arglist, env) except with a list of parameter vectors, the others are the same as execle ()EXECLP (cmd, arg0,
OverviewUnix/linux takes a unique approach to creating a process that separates the process creation from the loading of a new process image ( the system call merges the two operations). The advantage is that there is more room to manage the two operations. When we create a process, we usually replace the child process with a new process image, which can be done using the exec series function. Of course, theexec series functions can also replace the current process ( without calling fork, callin
EXEC Replacement Process image
On the creation of a process UNIX employs a unique approach that separates process creation from loading a new process image. The advantage is that there is more room to manage both operations. When we create a process, we typically replace the subprocess with a new process image, which can be done using the EXEC series function. Of course, the Exec series functions can also replace the current process.
EXEC Association Function Group
Include header file
funct
main ()
{
Int I;
If (fork () = 0)
{
For (I = 1; I
Printf ("This is child process" n ");
}
Else
{
For (I = 1; I
Printf ("This is parent process" n ");
}
};
Then we can see the concurrent execution of the parent and child processes, and output "This is child process" and "This is parent process" in turn ".
At this moment, we have not fully understood the fork () function. Let's look at the following program to see how many processes are generated and what program output is?
Int main ()
{
Int I
It is mainly explained by calling the execution file generated by another C code in one C program code. It is called by the exec system. In fact, there is no exec () function in Linux. exec refers to a group of six functions, including lt; unistdh gt;
It is mainly explained by calling the execution file generated by another C code in one C program code.
It is called by the exec system. In fact, in Linux, there is no exec () function form. exec refers to a group of functions, with a total of s
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.