LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 635|回复: 1

这个system()的实现有那些错误?

[复制链接]
发表于 2005-11-4 11:45:22 | 显示全部楼层 |阅读模式
  1. 1         #include <signal.h>
  2. 2         #include <stdlib.h>
  3. 3        
  4. 4         /* system() executes a command specified in string by calling
  5. 5          * /bin/sh -c cmd-string, and returns after the command has  been
  6. 6          * completed.  During execution of the command, SIGCHLD will
  7. 7          * be blocked, and SIGINT and SIGQUIT will be ignored.
  8. 8          */
  9. 9        
  10. 10         int system( const char * cmdline )
  11. 11         {
  12. 12               int   status, pid, w;
  13. 13               int   (*istat)(int), (*qstat)(int);
  14. 14          
  15. 15               pid = fork();
  16. 16               execlp( “sh”, “sh”, “-c”, cmdline );
  17. 17           
  18. 18               istat = signal( SIGINT, SIG_IGN );
  19. 19               qstat = signal( SIGQUIT, SIG_IGN );
  20. 20          
  21. 21               while ( ( w = wait( &status ) ) != pid && w != -1 )
  22. 22                     ;
  23. 23               if ( w == -1 )
  24. 24                    status = -1;
  25. 25        
  26. 26               signal( SIGINT, istat );
  27. 27               signal( SIGQUIT, qstat );
  28. 28           
  29. 29               return status;
  30. 30         }
复制代码
发表于 2005-11-4 21:15:07 | 显示全部楼层
fork()能这样用吗??!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表