forkbomb over 10W, god knows still some conflicts?
This commit is contained in:
parent
2f336e536b
commit
f886476139
@ -127,6 +127,8 @@ kern_fork(PROCESS_0 *p_fa)
|
|||||||
xchg(&p_fa->lock, 0);
|
xchg(&p_fa->lock, 0);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
while (xchg(&proc_child->pcb.lock, 1) == 1)
|
||||||
|
schedule();
|
||||||
PROCESS_0 *p_child = &proc_child->pcb;
|
PROCESS_0 *p_child = &proc_child->pcb;
|
||||||
// 再之后你需要做的是好好阅读一下pcb的数据结构,搞明白结构体中每个成员的语义
|
// 再之后你需要做的是好好阅读一下pcb的数据结构,搞明白结构体中每个成员的语义
|
||||||
// 别光扫一遍,要搞明白这个成员到底在哪里被用到了,具体是怎么用的
|
// 别光扫一遍,要搞明白这个成员到底在哪里被用到了,具体是怎么用的
|
||||||
@ -154,17 +156,17 @@ kern_fork(PROCESS_0 *p_fa)
|
|||||||
p_child->exit_code = p_fa->exit_code;
|
p_child->exit_code = p_fa->exit_code;
|
||||||
// p_child->fork_tree
|
// p_child->fork_tree
|
||||||
// p_child->kern_regs
|
// p_child->kern_regs
|
||||||
p_child->lock = 0;
|
// p_child->lock
|
||||||
// p_child->page_list
|
// p_child->page_list
|
||||||
p_child->pid = i;
|
p_child->pid = i;
|
||||||
p_child->priority = p_fa->priority;
|
p_child->priority = p_fa->priority;
|
||||||
p_child->statu = INITING; //! important!!! if you copied this from parent, haha, waste one hour
|
p_child->statu = INITING; //! important!!! if you copied this from parent, haha, waste one hour
|
||||||
p_child->ticks = p_fa->ticks;
|
p_child->ticks = p_fa->ticks;
|
||||||
p_child->user_regs = p_fa->user_regs;
|
p_child->user_regs = p_fa->user_regs;
|
||||||
|
ENABLE_INT();
|
||||||
//? 2. ALLOC PAGES AND COPY PHYSICAL MEMORY
|
//? 2. ALLOC PAGES AND COPY PHYSICAL MEMORY
|
||||||
copy_parent_pages(p_child, p_fa);
|
copy_parent_pages(p_child, p_fa);
|
||||||
// panic("Unimplement! soul torture1");
|
// panic("Unimplement! soul torture1");
|
||||||
ENABLE_INT();
|
|
||||||
//? 3. SET restart point
|
//? 3. SET restart point
|
||||||
// //! maybe, kern stack different, use offset relevant to stack base addr to set child's kern esp
|
// //! maybe, kern stack different, use offset relevant to stack base addr to set child's kern esp
|
||||||
// u32 esp_off = p_fa->kern_regs.esp - (u32)p_fa;
|
// u32 esp_off = p_fa->kern_regs.esp - (u32)p_fa;
|
||||||
@ -196,6 +198,7 @@ kern_fork(PROCESS_0 *p_fa)
|
|||||||
p_fa->fork_tree.sons = p_son;
|
p_fa->fork_tree.sons = p_son;
|
||||||
// 最后你需要将子进程的状态置为READY,说明fork已经好了,子进程准备就绪了
|
// 最后你需要将子进程的状态置为READY,说明fork已经好了,子进程准备就绪了
|
||||||
p_child->statu = READY;
|
p_child->statu = READY;
|
||||||
|
xchg(&p_child->lock, 0);
|
||||||
xchg(&p_fa->lock, 0);
|
xchg(&p_fa->lock, 0);
|
||||||
// 在你写完fork代码时先别急着运行跑,先要对自己来个灵魂拷问
|
// 在你写完fork代码时先别急着运行跑,先要对自己来个灵魂拷问
|
||||||
// 1. 上锁上了吗?所有临界情况都考虑到了吗?(永远要相信有各种奇奇怪怪的并发问题)
|
// 1. 上锁上了吗?所有临界情况都考虑到了吗?(永远要相信有各种奇奇怪怪的并发问题)
|
||||||
|
|||||||
@ -33,12 +33,11 @@ kern_wait(int *wstatus)
|
|||||||
// wait系统调用与exit系统调用关系密切,所以在实现wait之前需要先读一遍exit为好
|
// wait系统调用与exit系统调用关系密切,所以在实现wait之前需要先读一遍exit为好
|
||||||
// 可能读完exit的代码你可能知道wait该具体做什么了
|
// 可能读完exit的代码你可能知道wait该具体做什么了
|
||||||
// panic("Unimplement! Read The F**king Source Code");
|
// panic("Unimplement! Read The F**king Source Code");
|
||||||
|
again:
|
||||||
|
while (xchg(&p_proc_ready->pcb.lock, 1) == 1)
|
||||||
|
schedule();
|
||||||
PROCESS_0 *p_fa = &p_proc_ready->pcb;
|
PROCESS_0 *p_fa = &p_proc_ready->pcb;
|
||||||
int child_pid = -1;
|
int child_pid = -1;
|
||||||
again:
|
|
||||||
while (xchg(&p_fa->lock, 1) == 1)
|
|
||||||
schedule();
|
|
||||||
struct son_node* p_son = p_fa->fork_tree.sons;
|
struct son_node* p_son = p_fa->fork_tree.sons;
|
||||||
if (p_son == NULL) {
|
if (p_son == NULL) {
|
||||||
xchg(&p_fa->lock, 0);
|
xchg(&p_fa->lock, 0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user