Commit 91e0c0f5 authored by 一笑's avatar 一笑
Browse files

delete_document_old

No related merge requests found
Showing with 0 additions and 39 deletions
+0 -39
# define SYS_cps 22
功能:遍历所有进程控制块,并打印相关信息
**返回值:**成功执行,返回22,系统调用号
`cps();`
# 实现思路:
1. 定义结构体指针
-定义了一个指向struct proc类型结构体的指针p,并初始化为指向名为proc的结构体
2. 输出表头信息,并循环遍历
-通过for循环从proc开始(即数组首地址),一直遍历到proc[NPROC]之前(因为数组下标是从 0 到NPROC - 1),每次循环指针p会指向下一个进程控制块结构体元素
3. 输出进程状态信息
-根据三种进程状态(SLEEPING、RUNNING、RUNNABLE)输出相应信息
4. 如果成功返回22(系统调用号)
# 代码实现:
```c
int cps(void)
{
struct proc *p = proc; // 定义一个结构体(进程控制块)
// stati(); // 中断
printf("name \t pid \t state \t \t priority \tdyn_priority\n"); // 罗列所有的pid
for (p = proc; p < &proc[NPROC]; p++) // NPROC为64
{
if (p->state == SLEEPING) // 睡眠
printf("%s \t %d \t SLEEPING \t %d\t \t%d\n", p->name, p->pid, p->priority, p->dyn_priority);
else if (p->state == RUNNING) // 正在执行
printf("%s \t %d \t RUNNING \t %d\t \t%d\n", p->name, p->pid, p->priority, p->dyn_priority);
else if (p->state == RUNNABLE) // 可运行队列
printf("%s \t %d \t RUNNABLE \t %d\t \t%d\n", p->name, p->pid, p->priority, p->dyn_priority);
}
return 22; // 返回22
}
```
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment