The EXEC function of process and signal system function

Source: Internet
Author: User

exec function:

The child process calls the EXEC function to execute another program, and the EXEC function process is completely replaced by the new program, replacing the original program body, data, heap, and stack

#include <unistd.h>extern Char**environ;intEXECL (Const Char*path,Const Char*arg, ...);intEXECLP (Const Char*file,Const Char*arg, ...);intExecle (Const Char*path,Const Char*arg, ...,Char*Constenvp[]);intExecvConst Char*path,Char*Constargv[]);intEXECVP (Const Char*file,Char*Constargv[]);intExecve (Const Char*file,Char*ConstArgv[],Char*Constenvp[]); Exec function Error returned-1, success does not return

Execve are system functions, others are library functions

System functions

 #include <stdlib.h>int  system ( char  *command) Return: Command state returned successfully, error returned -1   function: The simplify EXEC function constructs a child process inside the system function, Calling the EXEC function by a child process is equivalent to /bin/bash-c  cmd   or exec ("  bash  , "   -C  , "   CMD  ) 
#include <unistd.h><stdlib.h><stdio.h>char *cmd1="/bin /date"; int Main (void) {    system ("clear");    System (CMD1);         return 0 ;}

system function Source code

#include <sys/types.h>#include<sys/wait.h>#include<errno.h>#include<unistd.h>intSystemConst Char*cmdstring)    {pid_t pid; intstatus; if(Cmdstring = =NULL) {                   return(1); }    if(PID = fork ()) <0) {Status= -1; }    Else if(PID =0) {execl ("/bin/sh","SH","- C", Cmdstring, (Char*)0); Exit (127); }    Else{             while(Waitpid (PID, &status,0) <0){                if(errno! =einter) {Status= -1;  Break; }            }        }        returnstatus;}

The EXEC function of process and signal system function

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.