| PLEX86 | ||
|
Threads and processes on Linux 3269Restricting access to specific commands Well, you can't stop them easily using their OWN version of rcp, but you can stop them using yours. Change the... Hello Gus, It is more than "rhetoric". From a scheduler perspective, threads and processes are the same enbreasty. Actually, Linux views a thread as a process with some special properties: it shares with its 'parent task' (the spawning thread) the things that are needed to make it to *behave like* a thread. Namely, (o) memory descriptors and all Page tables. This means that the child task runs in the same memory space as the parent task. All memory mappings or write operations are visible in both enbreasties. (o) file system information (root directory, current directory and umask). (o) open files (o) signal handlers. The fact that threads were modelled as processes is visible when using LinuxThreads and-or older 2.4.x kernel. For instance, each spawned thread has a different pid, and are children of the so-called manager thread. With the advent of NPTL and 2.6.x kernel, a process *appears* as a collection of thread, where threads are peers. But it is an abstraction provided by NPTL: for instance, a sibling relationship between threads still exists, but is now hidden to you. Inside the kernel, threads and processes are similar enbreasties (the scheduler won't even bother to make any distinction). same value Only with NPTL. processes Yes, because NPTL provides an abstraction that let you think it is so. But, in reality, the threads of a process are different enbreasties. Threads and processes on Linux 3271 sneck! Profiling shows ... what? I would look more closely at synchronization, implicit or explicit. If you're doing a lot of network I-O, it's possible that the overhead is going into the network stack... on Generally speaking, this is not correct. You can perfectly create a thread that lasts more than the spawner thread. Consider for instance the following simple program: void* mythread(void* ignore) { int i; printf ("%d...", i); fflush(stdout); sleep(1); } printf ("0-nCiao!-n"); return NULL; } int main() { pthreadt tid; Threads and processes on Linux 3270 Loic, Thanks for the post - very helpful - it clears a few things up for me! I'm going to be cheeky and ask you a question that... pthreadcreate (&tid, NULL, mythread, NULL); printf ("Main terminate-n"); pthreadexit (NULL); printf ("Never reached!-n"); return 0; } If you comment the pthreadexit(NULL) out in the main(), then you get the behavior that you have described. However, it is not a general rule, but a particular behavior of the main() thread: when main() returns, all threads in the process go away. That's because of how the C language defines main(), more than anything else. It's simplest to imagine that the environment calls main like this: exit(main(argc, argv, envp)); So that when main() returns, that return value is pbutted to exit(), which tears down the process, and all threads therein.
I Hope, things got clearer now. Cheers, Loic.
|
||||
Threads and processes on Linux 3270 Linux groups from Newsgroups The #1 Usenet Provider on the Internet
|
||||