Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!