Write one C program to measure the average time to create a thread using pthread_create() and to create a process using fork().
1. Use a for loop to create 300 threads using pthread_create(), and measure the total time to create these 300 threads. Then compute its average;
2. Use a for loop to create 300 processes using fork(), and measure the total time to create these 300 processes. Then compute its average;
Briefly describe the reasons for the difference in timings.
It needs to use gettimeofday() to retrieve the system time.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |