diff --git a/apps/src/init.c b/apps/src/init.c index f14ed480..e3ef8414 100644 --- a/apps/src/init.c +++ b/apps/src/init.c @@ -174,6 +174,14 @@ int main() } else { printf("Success!! Got PID %ld\n", child); } + child = fork(); + if (child < 0) + { + perror("fork"); + return 1; + } + if (child == 0) { *(int*)(0xdeadbeef) = 1234; } + int status; for (;;) { diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 43a30a03..a2f1eb02 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -287,8 +287,17 @@ void Scheduler::task_misbehave(Context* context, int64_t status) { ASSERT(Interrupts::is_in_handler()); kdbgln("exit: task %ld misbehaved, used %ld ms of cpu time", sched_current_task->id, sched_current_task->cpu_time); - sched_current_task->state = sched_current_task->Exited; + if (sched_current_task->id == 1) sched_current_task->state = sched_current_task->Exited; + else + sched_current_task->state = sched_current_task->Dying; sched_current_task->exit_status = status; + if (sched_current_task->id != 1) + { + sched_for_each_child(sched_current_task, [](Task* child) { + if (child->state != child->Exited) child->ppid = 1; + return true; + }); + } task_yield(context); }