Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
educg-net-28668-2608132
OSKernel2024-BirdOS-682
Commits
91e0c0f5
Commit
91e0c0f5
authored
6 months ago
by
一笑
Browse files
Options
Download
Patches
Plain Diff
delete_document_old
parent
d71ecb90
master
mq
test
yi12
yi1215
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
document/系统调用.md
+0
-39
document/系统调用.md
with
0 additions
and
39 deletions
+0
-39
document/系统调用.md
deleted
100644 → 0
+
0
−
39
View file @
d71ecb90
# 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
\t
dyn_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
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets