|
|
- 1 #include <signal.h>
- 2 #include <stdlib.h>
- 3
- 4 /* system() executes a command specified in string by calling
- 5 * /bin/sh -c cmd-string, and returns after the command has been
- 6 * completed. During execution of the command, SIGCHLD will
- 7 * be blocked, and SIGINT and SIGQUIT will be ignored.
- 8 */
- 9
- 10 int system( const char * cmdline )
- 11 {
- 12 int status, pid, w;
- 13 int (*istat)(int), (*qstat)(int);
- 14
- 15 pid = fork();
- 16 execlp( “sh”, “sh”, “-c”, cmdline );
- 17
- 18 istat = signal( SIGINT, SIG_IGN );
- 19 qstat = signal( SIGQUIT, SIG_IGN );
- 20
- 21 while ( ( w = wait( &status ) ) != pid && w != -1 )
- 22 ;
- 23 if ( w == -1 )
- 24 status = -1;
- 25
- 26 signal( SIGINT, istat );
- 27 signal( SIGQUIT, qstat );
- 28
- 29 return status;
- 30 }
复制代码 |
|