Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
Kernel: Right way to check if process is running in c

I want to check if a process which pid I have is running from an kernel extension.

In user-space this would be 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");

But somehow kill() is not available in kernel. Is there another approach to do this?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use pid_task() or get_pid_task() to get a pointer to the struct task_struct of the process. If the call returns NULL then the process does not exist.

Note that you may need to be careful as the pid might have been recycled and is now used by a different process.

over 4 years ago · Santiago Trujillo Denunciar

0

After Christophe's answer I found the a way to solve this.

//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);
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda