Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was wondering if 7735, 7736, 7737, 7743 were really processes. Then I checked /proc, I could cd to /proc/7735, /proc/7736, etc, but I could not ls them out.
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.
icecast2---13*[{icecast2}]
So, what does all this mean? Does it mean that 7735, 7736, 7737, 7743 are just threads but not processes? If so, why could I cd to /proc/<id> but not see them in "ps -elf".
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.
Last edited by neonsignal; 07-31-2009 at 12:17 AM.
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.
Thank you for your reply and the explanation!
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?
Good point. Looks like the old pthreads in Linux didn't comply to the POSIX standard and were a bit of a kludge (implemented by cloning processes).
The current pthread library (NPTL) does not have separate process ids for the threads (support for this library is in the 2.6 kernels).
Thank you Neon!
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".
Do you mean that programs can choose which thread library to use?
Sort of - my understanding is that the LinuxThread library is being phased out (it is not in the glibc anymore), in favor of the NPTL. So it will only be older projects like StarOffice that have what I will call 'pseudo-threads'.
Sort of - my understanding is that the LinuxThread library is being phased out (it is not in the glibc anymore), in favor of the NPTL. So it will only be older projects like StarOffice that have what I will call 'pseudo-threads'.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.