Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us | -->
Your current position : Homepage > Free Software > Technological exchanges >Application Programming -->


    

Blue Forest http://www.lslnet.com at 2:08 p.m. on August 16, 2006

Why use Linux programming process with fewer threads? A programming problems

Linux C and C + + programming process threads

Programming engaged Linux/UNIX years, has been using the fork in the process of writing more procedures. When friends ask why Linux rarely use when programming thread found myself really need to study this problem. Manual check fork man has been suggested by the following :
Fork creates a child process that differs from the parent process only in its PID and PPID. and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited.
Under Linux, fork is implemented using copy-on-write pages. so the only penalty incurred by fork is the time and memory required to duplicate the parent 's page tables. and to create a unique task structure for the child.
The only thing to do is fork duplicating page (page tables) and the creation of task structure. In addition, the process appears only difference is that his father PID and PPID of 0 and resource consumption.
However, if one examines the LinuxThreads PTHREAD_CREATE (3) is the creation of a thread only, and no mention of the relevant details.
Actual situation? I have prepared the following two codes :
*/ /*forktest.c As follows :
#include "Stdlib.h>
#include "Sys/types.h>
#include "Unistd.h>
#include "Unistd.h>
#include "Stdio.h>

Int main (int argc, char ** argv)
{
Pid_t pid;
Char * mem;
If (argc "4) {printf (" \r\nusage : %s time1 time2 memory-size\n "argv[0]); Return 1;}
Mem = (char *) malloc (atoi (argv[3])); LEAVES OF 13 SPECIES OF LAURACEAE tests the memory occupied by deliberately imported 1G or more memory demand */
Pid = fork ();
If (pid ====== 0) (
Sleep (atoi (argv[1]));
Exit (0);
}
Sleep (atoi (argv[2]));
Return 0
}
LEAVES OF 13 SPECIES OF LAURACEAE this translated into executable code procedures a-fork*/

*/ /*pthread_create.c As follows :
#include "Unistd.h>
#include "Pthread.h>
Void * start_routine (void * a)
{
Sleep (30);
}

Int main (int argc, char ** argv)
{
Int ret;
Pthread_t pth;
Ret = pthread_create (&pth, NULL, start_routine, NULL);
Sleep (35);
Return 0
}
LEAVES OF 13 SPECIES OF LAURACEAE this translated into executable code procedures a-thread*/

Then these two operating procedures, and the top order ps order observed that the surface has been as follows :
1, are two CPUs share %CPU 0
2, the two share a memory a-thread %MEM:a-fork 0.5 and 0.6
3, after the two procedures could see the two processes ps (process a-fork two a-thread process has two)

See the depth understanding of the phenomenon :
3 is due to the above results LinuxThreads threads and processes is used in the "one-to-one" model, the dispatch to the core, and in the realization of a user-level threads, including the signal processing and control mechanisms.
These results are in the process one should sleep, it is understandable that the bar did not occupy the CPU.
But why be the first two findings that the memory a-thread share even higher than a-fork? Although the symptoms can tell me why you like the process of programming and the use of thread programming, however true in the end Why? I have this to the test in the end not? (I also use their own PC in the test ah), it must carefully study kernel source code ah know.
Information available : Because of the unique advantages of Linux, the Linux process is more efficient, and lightweight, so the preferred Linux programming process.


Re : Why use Linux programming process with fewer threads? A programming problems

What's the
Among other nptl

Re : Why use Linux programming process with fewer threads? A programming problems

Kernel itself is said to be limited, no matter for what bars are not perfect

Re : Why use Linux programming process with fewer threads? A programming problems

Why is the process, the thread is not bad, but under most circumstances sufficient process, a very long process has been used Unix category, the late thread, standardization later. The realization of the process is gradually improving in their efficiency and Linux thread than no significant difference, such as building speed, data sharing, and synchronization mechanisms (use futex) not bad. Attention NPTL is the latest threads, but even so, the efficiency of the process is not bad. Noninterference while the process is characterized by a thread can not be achieved, the use of the process will be very extensive, particularly WWW/FTP server, of course, things like the GUI procedures for background music or the appropriate thread.

Re : Why use Linux programming process with fewer threads? A programming problems

Even together for kernel
If you are not, then 2.6



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com