Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CS 604 – Operating Systems

Assignment Solution

Student ID: BC190412088

Name: Faizan Ahmad

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 *frstThread(void *arg);

void *scndThread(void *arg);

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);

void *frstThread(void *arg)


{
printf("In First Thread\n");
printf("Faizan Ahmad\n");
printf("Father Name Muhammad Mushtaq\n");
printf("Thread ID\n %ld",pthread_self());
}
void *scndThread(void *arg)
{
printf("\nIn Second Thread ");
printf("VU ID BC190412088 \n");
printf("...Fateh Jang Campus\n");
printf("Thread ID:\n %ld", pthread_self());
}

Screenshot:
Question 2: In the following table, write the Linux command for the given details.

Detail. Linux Command


Command to search the file having the find /home Ali
name “Ali” under your home directory
using the find command. In case the file is
found write its name in the file “hello.txt”
inthe current directory by using the standard
output redirection
Use the standard output redirection through Cat > hello.txt
the cat command and write your name in the Ctrl+D
file name “hello.txt” in your current
directory and specify when you finish
writing.
Use the standard input redirection through Cat hello.txt
the cat command and read from the file
having the name “hello.txt” in the current
directory.

You might also like