Linux 系统调用中的系统调用

Linux 系统调用中的系统调用,linux,operating-system,kernel,Linux,Operating System,Kernel,您好,我正在尝试向lubuntu内核添加自定义系统调用。我正在尝试终止此系统调用中的进程。我尝试在原始ubuntu内核中终止系统调用。但我在做这件事时遇到了编译器错误。我不知道该怎么做才好。提前感谢您的回答 #define _POSIX_SOURCE #include <linux/syscalls.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/list.h&g

您好,我正在尝试向lubuntu内核添加自定义系统调用。我正在尝试终止此系统调用中的进程。我尝试在原始ubuntu内核中终止系统调用。但我在做这件事时遇到了编译器错误。我不知道该怎么做才好。提前感谢您的回答

#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,

}

您不能在像fork、kill、exit这样的系统调用中使用系统调用

kill系统调用通常用于发送到常规进程或多线程应用程序;其相应的服务程序是sys_kill函数

因此,您可以在内核级别使用sys_kill函数来终止进程

sys_kill的用法:

资料来源: Linux内核开发,Robert Love出版的第三版:Addison Wesley Professional,2010


注:2。“yapabildiniz mi”部分:

为什么要添加系统调用以终止进程?已经有这样的系统调用。显示您的代码并根据编译错误。然而,向内核添加系统调用是一项非常有趣的任务。请考虑各种教程,例如,您认为系统调用实际上是一个包装相应的系统调用的GLYBC函数。作为第一步,请仔细阅读本文件:我所说的仔细是指花30分钟。Saol cevap icin 2。基斯米·达·亚普提克=