system函数效率低,依赖信号,不妨用一下这种试试
int my_System(const char * cmdstring)
{
pid_t pid;
int status;
if(cmdstring == NULL)
{
return 1;
}
if((pid = vfork())<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 != EINTR)
{
status = -1;
break;
}
}
}
return status;
}