I found out that sys_kill can be used to kill process from a system call, but when i compile the following code, i get the following error:
error: implicit declaration of function ‘sys_kill’ [-Werror=implicit-function-declaration] long kill = sys_kill(pid,SIGKILL);
#define _POSIX_SOURCE #include <linux/kernel.h> #include <linux/unistd.h> #include <linux/module.h> #include <linux/init.h> #include <linux/sched.h> #include <linux/cred.h> asmlinkage long sys_killa(pid_t pid) { printk(KERN_INFO "Current UID = %un",get_current_user()->uid); printk(KERN_WARNING "The process to be killed is %d n", pid); long kill = sys_kill(pid,SIGKILL); printk(KERN_WARNING "sys kill returned %ldn", kill); return 0; }
Advertisement
Answer
It is often not possible to call the entry point of a system call from the kernel, since the API is for use from user space. Sometimes the functionality is provided in code close to the implementation code. It is usually made available throughout the kernel via an EXPORT_SYMBOL()
macro.
For the kill()
system call there is the internal kernel function kill_pid, with the declaration
int kill_pid(struct pid *pid, int sig, int priv)
You need to pass a struct pointer to the process, signal number, and boolean 1
. Look at other code making this call for how to do so.