Lab – Processes and Threads

Write a program that does the following:

  • When the program start fork a new child process. The father process should wait for the child process to finish.
  • The child process main thread should spawn 5 additional threads.
  • Each thread should print: “I am thread number n” and terminate.
  • The child process main thread should wait for all it’s threads to terminate. It should then print “Bye” and exit.
  • When the child exists, the father should print “Goodbye” and exit


  • To create a child process use – fork   (man 2 fork)
  • To wait for a child process use wait (man 2 wait)
  • to create a new thread use pthread_create (man pthread_create)
  • to wait for a child thread to exit use pthread_join (man pthread_join)