|
|
发表于 2005-9-12 17:38:28
|
显示全部楼层
system 调用是以SHELL的方式执行的。而且也不够灵活。建议直接用FORK EXEC系列。
man 2 fork
man 2 exec
- int main()
- {
- int pid = fork();
- switch(pid)
- {
- case -1:
- error ....
- break;
- case 0:
- //child ...
- execlp("cp","cp","source file","targetfile",(char *) 0);
- break;
- default:
- printf("cping ...... pls wait...");
- int s;
- wait(&s);
-
- }
- }
复制代码
如果想实现超时时KILL掉CP程序,可以试试 waitpid |
|