LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-09-2007, 02:11 AM   #1
psh2001
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,

Regards,
Shiv
 
Old 08-09-2007, 01:03 PM   #2
ta0kira
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.
ta0kira

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

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

Original Poster
Rep: Reputation: 0
ta0kira,

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.

Regards,
Shiv
 
Old 08-10-2007, 09:51 AM   #4
ta0kira
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.
ta0kira
 
Old 08-11-2007, 11:21 PM   #5
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,278

Rep: Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088
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.
 
  


Reply

Tags
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 01:21 AM
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM
How to View Threads per Process Shashi Linux - Software 0 08-01-2003 01:37 AM
Threads And Process Penguinizer Programming 1 02-18-2003 09:39 PM


All times are GMT -5. The time now is 08:26 PM.

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