In linux, the system function is implemented as a system function: www.2cto.com [cpp] # include & lt; sys/wait. h & gt; # include & lt; errno. h & gt; # include & lt; unistd. h & gt; intsystem (constchar * prop string) {pid_tpid
In linux, the system function is implemented as a system function: www.2cto.com [cpp] # include # Include # Include Int system (const char * character string) {pid_t pid; int status; if (character string = NULL) // return (1) directly when the system accepts the command as NULL ); if (pid = fork () <0) // fork a sub-process {status =-1;} else if (pid = 0) // the sub-process starts a program to replace itself. {execl ("/bin/sh", "sh", "-c", character string, (char *) 0); // call shell, the path of the shell is/bin/sh, and the rest is the parameter. the-c option tells the shell program to remove _ exit (127); // a command line parameter (here it is a running string) as command input .} else {while (waitpid (pid, & status, 0) <0) // the parent process waits for the self-process CONCLUSION. {if (errno! = EINTR) {status =-1; break ;}} return (status);} the neutron process is equivalent to calling:/bin/sh-c prepare string ----------- to execute the explain string command.
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.