【发布时间】:2017-03-22 13:50:57
【问题描述】:
大家好,我需要一点帮助。经过几个小时的学习和研究,我放弃了,我做不到。我是内核编程的新手,我有这个任务要做。我被要求修改 exit() 系统调用代码,使其终止调用进程的所有子进程,然后终止该进程。 据我所知,exit() 系统调用在父进程终止后将子进程提供给 init 进程。我想我可以通过使用孩子 ID 并调用来终止每个孩子:
kill (child_pid, SIGTERM);
我也知道我们可以使用 current 全局变量访问调用进程 task_struct。 任何人都知道我可以从 current 变量中获取所有孩子的 PID 吗?你知道其他解决方案吗?
更新: 我找到了一种如何遍历当前进程的子进程的方法。这是我修改后的代码。
void do_exit(long code)
{
struct task_struct *tsk = current;
//code added by me
int nice=current->static_prio-120;
if(tsk->myFlag==1 && nice>10){
struct task_struct *task;
struct list_head *list;
list_for_each(list, ¤t->children) {
task = list_entry(list, struct task_struct, sibling);
//kill child
kill(task->pid,SIGKILL);
}
}
这甚至会起作用吗?
【问题讨论】:
标签: linux-kernel operating-system kernel system-calls systems-programming