Home > Linux Kernel Misc > Find out if you are invoked by a kernel thread

Find out if you are invoked by a kernel thread

There may be times when you have patch in the kernel and either

a) Only want to execute if you are invoked by a kernel thread

b) Only want to execute if you are not invoked by a kernel theread

To find out if you are or are not, do this:

//get current task struct to see process info
struct task_struct* task = get_current();
//check if its a kernel thread
if (task->mm == NULL) {
//it’s a kernel thread
}
else {
//it’s not a kernel thread
}
Advertisements
Categories: Linux Kernel Misc Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: