fork() creates an exact copy of the calling process.
wait() blocks the calling process until a child changes state.
main()
pid_t pid
while iter-- > 0
switch pid = fork()
case 0 // child
exit(EXIT_SUCCESS)
case -1 // error
perror("fork() error:")
exit(EXIT_FAILURE)
default // parent
assert(wait(NULL) == pid)
pthread_create(&tid, f) creates a new thread.
tid contains the new thread's id.
f(), terminating when f() returns.
pthread_join(tid) blocks the caller until the thread with the
given id terminates.
static void f() { }
main()
while (iter-- > 0)
if e = pthread_create(&tid, f)
printf("create failed")
return EXIT_FAILURE
if e = pthread_join(tid)
printf("join failed")
return EXIT_FAILURE
See the complete code.
Linux version 2.4.20-30.9smp gcc version 3.2.2 Red Hat Linux 3.2.2-5 Memory: 1,310,712k available Processors: 2 Detected 728.493 MHz processor. CPU 16K L1 I cache, 16K L1 D cache CPU L2 cache: 256K
| Solaris | Linux | |
|---|---|---|
| Threads | 138 | 12 |
| Processes | 9077 | 722 |
iter = 2000.
This page last modified on 14 November 2004.