Quiero verificar si un proceso cuyo pid tengo se está ejecutando desde una extensión del kernel.
En el espacio de usuario esto sería simple:
if (kill(pid, 0) == 0) { printf("Process %d is running\n", pid); } else if (errno == ESRCH) { printf("Process %d is not running\n", pid); } else { printf("This shouldn't happen oO\n");Pero de alguna manera kill() no está disponible en el kernel. ¿Hay otro enfoque para hacer esto?
Puede usar pid_task() o get_pid_task() para obtener un puntero a la struct task_struct del proceso. Si la llamada devuelve NULL , el proceso no existe.
Tenga en cuenta que es posible que deba tener cuidado, ya que es posible que el pid se haya reciclado y ahora lo utilice un proceso diferente.
Después de la respuesta de Christophe, encontré la manera de resolver esto.
//necessary imports #include <linux/sched.h> #include <linux/pid.h> //Rest of your module pid_t pid = myPid; //integer value of pid struct pid *pid_struct = find_get_pid(pid); //function to find the pid_struct struct task_struct *task = pid_task(pid_struct,PIDTYPE_PID); //find the task_struct if (task == NULL) { printk (KERN_INFO "Process with pid %d is not running \n",argument); } else{ printk (KERN_INFO "Process with pid %d is running \n",argument); }