Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
21573833
提交
21573833
5月 31, 2009
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move fork into proc.c
上级
dae9b0d4
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
28 行删除
+25
-28
defs.h
defs.h
+4
-3
proc.c
proc.c
+20
-14
sysproc.c
sysproc.c
+1
-11
没有找到文件。
defs.h
浏览文件 @
21573833
...
@@ -94,6 +94,7 @@ int pipewrite(struct pipe*, char*, int);
...
@@ -94,6 +94,7 @@ int pipewrite(struct pipe*, char*, int);
// proc.c
// proc.c
struct
proc
*
copyproc
(
struct
proc
*
);
struct
proc
*
copyproc
(
struct
proc
*
);
void
exit
(
void
);
void
exit
(
void
);
int
fork
(
void
);
int
growproc
(
int
);
int
growproc
(
int
);
int
kill
(
int
);
int
kill
(
int
);
void
pinit
(
void
);
void
pinit
(
void
);
...
@@ -146,9 +147,9 @@ void tvinit(void);
...
@@ -146,9 +147,9 @@ void tvinit(void);
extern
struct
spinlock
tickslock
;
extern
struct
spinlock
tickslock
;
// uart.c
// uart.c
void
uartinit
(
void
);
void
uartinit
(
void
);
void
uartintr
(
void
);
void
uartintr
(
void
);
void
uartputc
(
int
);
void
uartputc
(
int
);
// number of elements in fixed-size array
// number of elements in fixed-size array
...
...
proc.c
浏览文件 @
21573833
...
@@ -130,34 +130,40 @@ usegment(void)
...
@@ -130,34 +130,40 @@ usegment(void)
// Create a new process copying p as the parent.
// Create a new process copying p as the parent.
// Sets up stack to return as if from system call.
// Sets up stack to return as if from system call.
// Caller must set state of returned proc to RUNNABLE.
// Caller must set state of returned proc to RUNNABLE.
struct
proc
*
int
copyproc
(
struct
proc
*
p
)
fork
(
void
)
{
{
int
i
;
int
i
,
pid
;
struct
proc
*
np
;
struct
proc
*
np
;
// Allocate process.
// Allocate process.
if
((
np
=
allocproc
())
==
0
)
if
((
np
=
allocproc
())
==
0
)
return
0
;
return
-
1
;
// Copy process state from p.
// Copy process state from p.
np
->
sz
=
p
->
sz
;
np
->
sz
=
c
p
->
sz
;
if
((
np
->
mem
=
kalloc
(
np
->
sz
))
==
0
){
if
((
np
->
mem
=
kalloc
(
np
->
sz
))
==
0
){
kfree
(
np
->
kstack
,
KSTACKSIZE
);
kfree
(
np
->
kstack
,
KSTACKSIZE
);
np
->
kstack
=
0
;
np
->
kstack
=
0
;
np
->
state
=
UNUSED
;
np
->
state
=
UNUSED
;
return
0
;
return
-
1
;
}
}
memmove
(
np
->
mem
,
p
->
mem
,
np
->
sz
);
memmove
(
np
->
mem
,
c
p
->
mem
,
np
->
sz
);
np
->
parent
=
p
;
np
->
parent
=
c
p
;
*
np
->
tf
=
*
p
->
tf
;
*
np
->
tf
=
*
c
p
->
tf
;
for
(
i
=
0
;
i
<
NOFILE
;
i
++
)
// Clear %eax so that fork returns 0 in the child.
if
(
p
->
ofile
[
i
])
np
->
tf
->
eax
=
0
;
np
->
ofile
[
i
]
=
filedup
(
p
->
ofile
[
i
]);
np
->
cwd
=
idup
(
p
->
cwd
);
return
np
;
for
(
i
=
0
;
i
<
NOFILE
;
i
++
)
if
(
cp
->
ofile
[
i
])
np
->
ofile
[
i
]
=
filedup
(
cp
->
ofile
[
i
]);
np
->
cwd
=
idup
(
cp
->
cwd
);
pid
=
np
->
pid
;
np
->
state
=
RUNNABLE
;
return
pid
;
}
}
// Set up first user process.
// Set up first user process.
...
...
sysproc.c
浏览文件 @
21573833
...
@@ -8,17 +8,7 @@
...
@@ -8,17 +8,7 @@
int
int
sys_fork
(
void
)
sys_fork
(
void
)
{
{
int
pid
;
return
fork
();
struct
proc
*
np
;
if
((
np
=
copyproc
(
cp
))
==
0
)
return
-
1
;
pid
=
np
->
pid
;
// Clear %eax so that fork returns 0 in the child.
np
->
tf
->
eax
=
0
;
np
->
state
=
RUNNABLE
;
return
pid
;
}
}
int
int
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论