Difference between Child THREAD and Child PROCESS
Hello,
I am troubleshooting something and I got this problem. If I do "pstree -p" It shows, Code:
Code:
ps -elf | grep soffi I looked at the man page of "pstree", it says, Code:
Child threads of a process are found under the parent process and are shown with the process name in curly braces, e.g. Would somebody please help me? Thanks! whho |
In a multitasking system, whether running on multiple CPUs/cores or not, the aim is to make it look like you can execute more than one task at the same time.
Both processes and threads refer to a type of multitasking (ie, separate streams of execution). As we currently use the terms, the main distinction is that processes have their own context (usually meaning data space), while threads have a shared context. Because of this, you end up with a hierarchy, with each process having one or more threads. Early Unix systems only had 'processes'. The advantage of threads is that the CPU can switch from thread to thread without having to also change all the address context state, which reduces overheads. So they have been implemented as a second layer. Older commands such as ps were originally written when there were no threads. |
Quote:
I am wondering if there is any command to view or manage the threads, like killing them and so on. I know that fork() can spawn a new process? How can I spawn a new thread? Thanks again! whho |
|
If threads are not processes, why are they assigned a process id? (or is it really a process id?)
|
Quote:
The current pthread library (NPTL) does not have separate process ids for the threads (support for this library is in the 2.6 kernels). |
Quote:
Do you mean that programs can choose which thread library to use? If they choose to use an old one, they end up creating threads implemented by process-like clones with different pids, right? I just felt that it was a bit weird or inconsistent when I could do "ls /proc/7735" but couldn't do "ls /proc/ | grep 7735". Thanks again! whho |
Quote:
|
Quote:
|
When I did threads in Perl (Perl is written in C, like most higher level langs), the kernel version was the determining factor: 2.4.x meant I'd see each thread as a separate process id. 2.6.x meant I'd only see the one pid for the main process.
HTH |
Something I'd like to throw in is that in a cluster environment, processes are able to migrate while threads are not. (A cluster is where you have a multitude of computers networked together and they collaborate to accomplish a given task.)
I used OpenMosix for this a while back and was surprised at how efficient things went after modifying my program to be multi-process. Basically, I had a large amount of data to process and then write to a database. I read the file and spawned a separate process for each record, having the results dumped to a file via a network port. Each process received the string, chewed on it as long as it needed to, and wrote out the results. It was very simple to migrate and easy to control with the Parallel::ForkManager perl module. I used an OpenMosix LiveCD on a bunch of workstations after hours and accomplished in one night what would've taken my box over two months to do! :) Threads were useless for this though; since they share memory with the calling application, they couldn't migrate to another machine. |
Thread and process
|
This thread is over 5 yrs. old.
|
All times are GMT -5. The time now is 02:28 AM. |