- #include "apue.h"
-
-
int main(int argc ,char * argv[])
-
{
-
int status;
-
-
if (argc < 2)
-
err_quit("command required ");
-
-
if ((status = system(argv[1])) < 0)
-
err_sys("system() error");
-
pr_exit(status);
-
exit(0);
-
}
- #include "apue.h"
-
#include <sys/wait.h>
-
-
void pr_exit(int status)
-
{
-
if (WIFEXITED(status))
-
printf("normal termination ,exit status = %d \n",WEXITSTATUS(status));
-
else if (WIFSIGNALED(status))
-
printf("abnormal termination signal nuber =%d %s\n",WTERMSIG(status),
-
#ifdef WCOREDUMP
-
WCOREDUMP(status) ? "(core file generated",:" null");
-
#else
-
"null");
-
#endif
-
else if (WIFSTOPPED(status))
-
printf("child stopped,signal number = %d\n",WSTOPSIG(status));
-
printf("just for test the exit \n");
-
}
- Script started on Fri 17 Feb 2012 09:10:43 PM CST
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ ls -lai tsys
-
-
791487 -rwxrwxr-x 1 ubuntu ubuntu 7913 2012-01-05 18:45 [
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ ^C
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ tsys "sleep 60"
-
^Cabnormal termination signal nuber =2 null
-
-
just for test the exit
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ ./tsys "sleep 60"
-
-
^\abnormal termination signal nuber =3 null
-
-
just for test the exit
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ sh
-
-
$ sh -c "sleeop 60"
-
-
^C
-
-
$ echo $?
-
-
130
-
-
$ sh -c "sleeopp 60"
-
-
^\Quit
-
-
$ echo $?
-
-
131
-
-
$ exit
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ ./tsys "sleep 60" &
-
-
[1] 3124
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ ps -f
-
-
UID PID PPID C STIME TTY TIME CMD
-
-
ubuntu 3058 3057 0 21:10 pts/0 00:00:00 bash -i
-
-
ubuntu 3124 3058 0 21:12 pts/0 00:00:00 ./tsys sleep 60
-
-
ubuntu 3125 3124 0 21:12 pts/0 00:00:00 sh -c sleep 60
-
-
ubuntu 3126 3125 0 21:12 pts/0 00:00:00 sleep 60
-
-
ubuntu 3127 3058 0 21:12 pts/0 00:00:00 ps -f
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ kill -KILL 3125
-
-
abnormal termination signal nuber =9 null
-
-
just for test the exit
-
-
[1]+ Done ./tsys "sleep 60"
-
-
ubuntu@ubuntu-virtual-machine:~/Desktop/apue/ch8$ exit
-
-
exit
-
-
-
Script done on Fri 17 Feb 2012 09:13:05 PM CST
需要注意的是,直接调用的返回值和shell的终止状态时不一样的,在着,直接运行该程序,然后kill的返回值和书上说的不一样,这里直接返回了信号值,杀死调用shell的返回值和直接调用system的值也是
不一样的
阅读(1440) | 评论(0) | 转发(0) |