MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / ReparentChildren

Method ReparentChildren

src/task/task_manager.cpp:284–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282}
283
284auto TaskManager::ReparentChildren(TaskControlBlock* parent) -> void {
285 if (!parent) {
286 return;
287 }
288
289 // init 进程的 PID 通常是 1
290 /// @todo 当前的 pid 是自增的,需要考虑多核情况
291 static constexpr Pid kInitPid = 1;
292
293 LockGuard lock_guard{task_table_lock_};
294
295 // 遍历所有任务,找到父进程是当前任务的子进程
296 for (auto& [pid, task] : task_table_) {
297 if (task && task->aux->parent_pid == parent->pid) {
298 // 将子进程过继给 init 进程
299 task->aux->parent_pid = kInitPid;
300 klog::Debug("ReparentChildren: Task {} reparented to init (PID {})",
301 task->pid, kInitPid);
302 // 如果子进程已经是僵尸状态,通知 init 进程回收
303 /// @todo 实现向 init 进程发送 SIGCHLD 信号
304 }
305 }
306}
307
308auto TaskManager::GetThreadGroup(Pid tgid)
309 -> etl::vector<TaskControlBlock*, kernel::config::kMaxReadyTasks> {

Callers

nothing calls this directly

Calls 1

DebugFunction · 0.85

Tested by

no test coverage detected