1:execl,execv,system的使用例子:
结果:
root@ubuntu:/home/jhw/whj/17-3-4# ./1 total 40 drwxr-xr-x 2 root root 4096 3月 3 22:40 . drwxr-xr-x 18 root root 4096 3月 8 12:54 .. -rwxr-xr-x 1 root root 7828 2月 11 11:05 1 -rwxr-xr-x 1 root root 11984 2月 20 22:35 2 -rw-r--r-- 1 root root 5654 3月 3 22:40 2.c -rw-r--r-- 1 root root 605 2月 19 22:22 3.c
结果:
root@ubuntu:/home/jhw/whj/17-3-4# ./1 Please enter the 1d num:1 cd 32 Please enter the 2d num:^C
注意点:char * argv[ ] = {...,NULL};最后有NULL。
结果:
root@ubuntu:/home/jhw/whj/17-3-4# ./1 total 40 drwxr-xr-x 2 root root 4096 3月 3 22:40 . drwxr-xr-x 18 root root 4096 3月 8 12:54 .. -rwxr-xr-x 1 root root 7828 2月 11 11:05 1 -rwxr-xr-x 1 root root 11984 2月 20 22:35 2 -rw-r--r-- 1 root root 5654 3月 3 22:40 2.c -rw-r--r-- 1 root root 605 2月 19 22:22 3.c
2:exit和_exit区别:
exit:在停止进程之前,先检查文件的打开情况,并把文件的缓冲区的内容写回文件才停止进程。
_exit:直接停止进程,清除使用的内存,并清除缓冲区的内容。
3:无名管道pipe:
结果:
root@ubuntu:/home/jhw/whj/17-3-4# ./4 The father process is 100 root@ubuntu:/home/jhw/whj/17-3-4# the child process is Hello everyone!
4:wait:
结果:
root@ubuntu:/home/jhw/whj/17-3-4# ./wait This child process is 3980 :This father process is 3980
wait返回值为子进程PID。
