This is the first programming job of the operating system principle course, which complements the functionality of the shell.The main implementation of the basic three types of commands
Executable program Commands
REDIRECT Command
Pipeline command
The implementation of the "base class" (Forgive me for using this word) is a struct cmd this struct is a member that is used to record the type of command.Three classes, "means executable program ' | ' represents the pipeline comm
can call the fork function to create a new process, and then call any exec function to regenerate the child process.
(3) exec function family syntax
In fact, in Linux, there are no exec functions, but six Function Families starting with exec. The following table lists the syntax of the six member functions of the exec function family.
Header files
# Include
Function Description
Execution File
Function prototype
Int execl (const char * path, const char * Arg
Under the Windows platform, we can run the executable program by double-clicking, let this executable program become a process, and on the Linux platform, we can pass ./ Run, let an executable program become a process.However, if we are running a program (process), how do we start an external program inside the process, and the kernel reads the external program into memory so that it executes as a process? Here we implement through the EXEC function family.The EXEC function family, as the name i
");if(Execl ("/bin/ls","ls"," -a", NULL) = =-1) {perror ("Execl Error"); Exit1); } }/** * Create a child process and call a function execv a pointer in the *EXECV that you want to receive a null-terminated array of strings * / if(fork () = =0) {// in childprintf"2------------execv------------\ n");if(Execv ("/bin
function executes successfully, it does not return, and the process ends. But if the EXEC function fails, it returns the failed information, and the process continues to execute the following code!Normally exec will be placed in the sub-process portion of the fork () function to replace the child process execution, and the subroutine disappears after execution succeeds, but the exit () function must be used to exit the child process if execution fails!Here are the various examples:2.1
2015.3.2There are three different processes and procedures:1, there are different locations, programs: Hard disk, disk. Process: Memory2. The program is static and the process is dynamicExecute the./a.out-->bash->bash Program Call Fork ()--and the child process will store the parameters after the./a.out to argv[]. Then call exec to process these parameters, and the last child process exits with the cursor flashingProcess into the Stop state: 1, debugging, 2, the foreground into the background to
do I need to write time copy technology ... First write-time copy is a delaying tactic of our program, if not Execv a series of functions, it is estimated that there will be no write-time copy of the appearance,Execv is to replace this program completely into another program, it is to Vm_area_ Linear list in struct, Rb_node red-black tree, physical pages, page tables, page directories are deleted, and the
Method 1: # include Method 2: exec () function familyNext let's take a look at how a process can start the execution of another program. Use the exec function family in Linux. The system calls execve () to replace the current process with a specified program. Its parameters include the file name (filename), the parameter list (argv), and the environment variable (envp ). Of course, there are more than one exec function family, but they are roughly the same. In Linux, they are: execl, execlp, exe
Inter-process communication between embedded Linux (II.)--exec family function exec The function family does this by locating the executable file according to the specified file name and substituting it for the contents of the calling process, in other words, executing an executable file inside the calling process. The executable file here can be either a binary file or a script file that can be executed under any Linux . The exec family functions include the following functions:#include extern
Control primitives. Fork allows you to create a new process with exec to execute the new program. Exit Function and two wait function processingTerminate and wait for termination. These are the basic process control primitives that we need. These primitives will be used in subsequent sections to construct additional functions such as popen and system.#include int execl (const char * pathname, const char *arg 0, .../* (char *) 0 */);int execv (const c
Inux Process Control-exec series is called the exec system call, actually in Linux, there is no EXEC () function form, exec refers to a set of functions, a total of 6, respectively:#include int execl (const char *path, const char *arg, ...);int EXECLP (const char *file, const char *arg, ...);int execle (const char *path, const char *arg, ..., Char *const envp[]);int execv (const char *path, char *const argv[]);int EXECVP (const char *file, char *const
()4 {5 //Create a new process6System"ls-a");7printf"over\n");8 9 Ten return 0; One}(2) The Exel family contains members (EXECL,EXECLP,EXECLE,EXECV,EXEVP,EXECVE);The Exel series function is a replacement creation process (the child process replaces the original process, and the parent process does something different), and only the PID remains the same (and the exec process PID is called);Some of its prototypes are as follows:int EXELC (co
, interesting, right? LD_PRELOAD is not exclusive to linux systems and is generally used in some applications (for example, StarOffice of earlier versions needs to run on a newer version of Redhat system) they must use their own library functions (older or modified) because they do not meet their needs during installation. Quantum (author of The Staog virus) provides the code in the Unix virus email list. I have modified the Code to make it easy for everyone to understand:./t | = 5--------------
only way to create a new process.
Details about exec system calls
In fact, there is no system call called "exec". The so-called "exec" system call is actually six system calls named in the form of execAB. The matching method is shown in:
Here, A can be l or v, depending on whether the parameter is directly in the call (list) or in the array (vector); B either does not exist or is p, p indicates to use the path environment variable to find the program, or e indicates to use the specific enviro
-defined interrupt processing function, such as signal 2, which corresponds to the exit (0) function call. The rest of the signals are not pre-defined interrupt handlers, and the signals of those predefined terminal handlers correspond to a function that resembles an empty function. Question: When you fork a child process, is the interrupt vector table of the child process the same as the parent process?The child process inherits the interrupt vector table of the parent process, provided that th
binary program into memory, replacing the previous contents of the address space, and begins execution The new programForkSystem Call:create A new Processto execute a new program in a new Process:first a fork to create a new process, and then An exec-to-load a new binary into that process EXEC series function,only Execve is a system call, the rest of the functions are the C-language library functions that are encapsulated according to EXECVE. After the system call, the child process is almost i
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.