您好我正在尝试向lubuntu内核添加自定义系统调用。我试图在此系统调用中终止一个进程。我在原来的ubuntu内核中尝试过kill()系统调用。但是这样做时我遇到了编译器错误。我不知道如何正确地做到这一点。提前感谢您的回答。
#define _POSIX_SOURCE
#include <linux/syscalls.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/signal.h>
#include <linux/types.h>
asmlinkage long sys_my_process_terminator (pid_t pid , int flag)
{
struct task_struct *task;
struct list_head *list;
struct list_head *siblist;
// firstly check the flag
struct task_struct *myprocess;
struct task_struct *sibchild;
myprocess = find_task_by_vpid(pid);
struct task_struct *pp;
pp =myprocess->parent;
if (flag == 0){
// this loop under this comment will kill all the children of the given process
list_for_each(list, &myprocess->children) {
task = list_entry(list, struct task_struct, sibling);
printk ("%s [%d] \n" , task->comm , task->pid);
kill(task->pid,SIGKILL);
}
}
else if (flag==1) {
list_for_each(list, &pp->children) {
task = list_entry(list, struct task_struct, sibling);
list_for_each(siblist, &task->children) {
sibchild = list_entry(siblist, struct task_struct, sibling);
printk ("%s [%d] \n" , sibchild->comm , sibchild->pid);
kill(sibchild->pid,SIGKILL);
}
if (task->pid !=pid){
printk ("%s [%d] \n" , task->comm , task->pid);
kill(task->pid,
}
答案 0 :(得分:0)
您不能在系统调用中使用系统调用,例如fork,kill,exit。
kill()系统调用通常用于发送到传统进程或多线程应用程序;其相应的服务例程是sys_kill()函数。
因此,您可以在内核级别使用sys_kill()函数来终止进程。
sys_kill()的用法: https://www.kernel.org/doc/htmldocs/device-drivers/API-sys-kill.html
和源书: “Linux内核开发,第3版”作者:Robert Love(出版商:Addison Wesley Professional,2010)
注意:2。Part'ıyapabildinizmi ?? :)