- #include <sys/types.h>
- #include <sys/wait.h>
- #include <errno.h>
- #include <unistd.h>
- int system(const char * cmdstring)
- {
- pid_t pid;
- int status;
- 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;
- }
- }
- }
- return status;
- }
版权声明:本文为博主原创文章,未经博主允许不得转载。