进程之Process Control实验(二)
2018-02-27 22:15
197 查看
1. 实验
Write a program that creates a zombie, and then call system to execute the ps(1) command to verify that the process is a zombie.2. 代码展示
#include <unistd.h> #include <stdio.h> #include <err.h> #include <stdlib.h> #define handle_error(msg) \ do { perror(msg); exit(EXIT_FAILURE);} while (0) int main( int agrc, char ** argv) { pid_t pid; if((pid = fork())<0) handle_error("fork"); if(pid == 0) { exit(0); } else { if(system("ps -o pid,ppid,pgid,sid,comm") == -1) handle_error("system"); } }
执行结果如下:
[root@localhost ~]# ./8_1 PID PPID PGID SID COMMAND 1040 1039 1040 1040 bash 1319 1040 1319 1040 8_1 1320 1319 1319 1040 8_1 <defunct> 1321 1319 1319 1040 ps
从结果可得
8_1的子进程
1320确实为僵尸进程,而
ps命令的父进程为
8_1,这点值得注意。
3. 题外话
第8章的实验比较简单,虽然有其他的题目,但是笔者筛选了下,就做了这个。也没有过分深究一些现象,总是把握主要矛盾,之前深究的细节也随着时间又淡忘了,看来学习知识也讲究实用主义,并非面面俱到就是好的。相关文章推荐
- 进程之Process Control(一)
- 进程上下文,pcb结构(process control block)
- 操作系统02进程管理Process_Description_and_Control
- 进程process与线程thread
- Linux进程实验~
- 操作系统 实验三 进程调度模拟程序
- 【操作系统】实验三 进程调度模拟程序
- 实验三、进程调度模拟程序实验
- 实验三 进程调度模拟程序
- 1、oracle后台进程(数据字典V$BGPROCESS)
- 操作系统进程优先级调度实验
- 内核进程创建之分配task_struct(do_fork->copy_process->dup_task_struct())
- 实验三 进程调度模拟程序
- The Process Address Space(进程地址空间)
- 挂接CreateProcessW实现对进程创建的完全控制
- CreateProcessAsUser,C#写的windows服务弹框提示消息或者启动子进程
- Android上app_process启动java进程
- Android 进程生命周期 Process Lifecycle
- 利用GetProcessMemoryInfo 获取进程内存使用
- Control.ProcessDialogKey 方法 ——用以处理对话框按键(TAB ESC 箭头键 等)