CENG 328 OPERATING SYSTEM LAB WORK 5

Threads and pipes

You should complile with -lpthread, such as

gcc -o thread thread.c -lpthread

thread.c Inverstigate the code and give command “thread mesaj”. Try without any mesaj, just as “thread”, What “NULL” corresponds for.

thread1.c Execute several times, and check the change in thread_id, if there is not, why?

thread2.c Study the code and describe the functionality.

thread3.c Study the code and describe the functionality.

thread4.c Study the code and describe the functionality. Try to write the without struct.

pipe.c Describe how pipe() system call works.

pipe1.c read_pipe.c Compile both programs and execute as “pipe1 10”, execute several times by changing the seed each time

signal.c Study the code and describe the functionality.

signal1.c Study the code and describe the functionality. Break with Ctrl+Z, you will get

[1]+ Stopped signal1

then kill the stopped process with “kill %1”.


Invesigate the following program1 and program2 for creating 4 threads (These codes should be compiled in SUN Lab). Each thread will increment the value of a global variable by one for 1000 times. Study the followings;