Professional Documents
Culture Documents
Assignment Solution
Assignment Solution
Assignment Solution
Question 1: You are required to create the two user-level threads by using the pthread_create()
library call. Following are thefunctionalities carried out by two thread functions.
First thread should print your name and father’s name and finally print the thread id by
usingthe pthread_self() library call.
Second thread should Print your VUID and campus address followed by the thread id by
using the pthread_self() library call.
In the main function call the pthread_join() so that the main() function can wait for the two
threads and finally, printthe message exiting the main function. The following should be the
flow of your program.
Firstly, compile your c program and also link the pthread library at the compile timeand
also use the REENTRANT macro from the command line.
Run your program.
You are required to send the screenshot along with C Code.
Answer: C Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <pthread.h>
void main()
{
pthread_t thread1;
pthread_t thread2;
pthread_create(&thread1, NULL, frstThread, NULL);
pthread_join(thread1, NULL);
pthread_create(&thread2, NULL, scndThread, NULL);
pthread_join(thread2, NULL);
printf("\nExiting the main function. \n");
exit(0);
Screenshot:
Question 2: In the following table, write the Linux command for the given details.