简体   繁体   中英

Killing a process using pid and finding user tied to pid in system call

I'm trying to develop a system call that is able to receive pid as argument, kill the pid and print to the kernel log. So far I have the code below but i get this error when trying to compile the kernel. How do i fix this? And is there a way to find the username of that killed the pid that is to be killed in this case?

kill_log/kill_log.c:2:24: fatal error: signal.h: No such file or directory compilation terminated. scripts/Makefile.build:289: recipe for target 'kill_log/kill_log.o' failed make[1]: * [kill_log/kill_log.o] Error 1 Makefile:968: recipe for target 'kill_log' failed make: * [kill_log] Error 2

#include <linux/kernel.h>
#include <signal.h>

asmlinkage long sys_kill_log(pid_t pid)
{
    kill(pid, SIGUSR1);
    printk(KERN_WARNING "The process %d has been killed\n", pid);

    return 0;
}

Based on your error message, you're missing signal.h . On debian-based systems, you would need to install libc6-dev .

In regards to retrieving the username, you could try with getpwuid .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM