ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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 ?
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.
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)
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.