Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

To compile your program you need to link the pthread library:

$ gcc –o ExecutableFile source.c -lpthread


1. (10 points) Compile and run the program above which creates two threads and
each thread is assigned the task of displaying a message.

2. (10 points) Run the code again this time in the background ( $ ./threads & ) Try
to terminate the program by sending a CTRL C signal. Explain the result.

^c
3. (10 points) What happens if the main thread does not wait for the other two threads?

If we remove main process other sub process should be remove.


So, It will kill the main thread it will automatically terminate the other
2 threads.

4. (10 points) Determine the storage class (automatic, static, global, register) for
each variable in this program.

automatic storage type


In main function
int i;
const int N = 2;
pthread_t tid[N];
char *msgs[N];
In thread
int myid;
int i;
global storage type
char ** ptr;
static storage type
int cnt = 0;
register storage type
void * vargp;

5. (10 points) Determine the memory segment (Text, Data, BSS, Stack, Heap) in the
process address space where memory is allocated for each variable in this program.
using size command we can find text, data, BSS size.
text = 2837 (size of file)
data = 664
BSS = 16
stack = 36
Here no dynamic allocation of memory so heap size will be 0.
OUTPUT:

You might also like