Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-09-2007, 03:11 AM   #1
LQ Newbie
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
what happens to threads if i kill the process ?

Hi ,
I am using the Linux 2.6 kernel.

I have an application which creates multiple threads.

And then i have a driver which is opened by the application process.

If i kill the process(abnormally) ,will the threads also be killed ?

Also the pid alive function shows the application process as alive .

Also 2nd question is ,the threads created in the application at some point of time have to execute in kernel context. So if i print the Process ID it shows differnet PID for each thread. So Are kernel threads and process are maintained by the same mm_struct ?

Pls let me know your comments,

Old 08-09-2007, 02:03 PM   #2
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Threads exist in the same process space as the main function. The main function of the program is a thread itself, and signals happen independently of that thread. As long as the signal is being handled (if it is,) the threads keep processing. When the default handler gets called the _exit cleanup function isn't called, so nothing gets cleaned up. The threads are just different contexts from the same memory space that the kernel switches out, so when the process is killed it just stops switching out the associated threads. If you really think about it, unless a thread has to clean something up outside of the process space (such as shared memory,) it doesn't make much of a difference for the process to be instantly terminated.

edit: We may be talking about different types of thread.

Last edited by ta0kira; 08-09-2007 at 02:08 PM.
Old 08-10-2007, 07:54 AM   #3
LQ Newbie
Registered: Aug 2007
Posts: 2

Original Poster
Rep: Reputation: 0

Thanks for your reply,
I have one more concern.
In linux there's no connection b/w user space threads (i.e POSIX based) and Kernel threads.
But i also heard that there's a one to one mapping for the user to kernel threads.

My concern is ,if that user thread is executing in one of the kernel thread ,and if the parent process which opened the driver get killed (this is one of the abnormal scenario's) ,what will happen to this kernel thread ?

Also in driver release function ,in normal scenario, the parent process will be having the current context.But since the parent process is killed ,one of the threads is getting the current context. Why is this so ?

Currently what i see is that the threads are not getting killed.
Also if i check the task_struct list by using the function

static inline int pid_alive(struct task_struct *p)

it shows the killed process as alive.

Pls let me know if you have any idea on this.

Old 08-10-2007, 10:51 AM   #4
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I haven't done a whole lot of kernel programming. Mostly just simple crypto modules. Sorry.
Old 08-12-2007, 12:21 AM   #5
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185
The most-appropriate design for a device driver is that any and all kernel-threads which may be associated with the driver are thought-of as belonging to the device, not to any of the user processes and/or threads which may have opened the device.

The user-land activity, no matter what it may be and no matter which or how-many threads or processes may be involved, "is simply 'customers to be served,' and nothing more." Just as a fast-food restaurant does not increase or decrease the number of employees as the crowds come and go, neither should your device driver.


process, threads

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to increase number of threads per process? Vaish Linux - Distributions 8 02-25-2010 02:21 AM
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 09:57 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 03:32 PM
How to View Threads per Process Shashi Linux - Software 0 08-01-2003 02:37 AM
Threads And Process Penguinizer Programming 1 02-18-2003 10:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration