Reference no: EM132229848
Operating Systems Assignment - Process/thread creation and inter-process communication
Goals
Practise:
1. process creation in Linux using fork() and exec() system calls
2. thread creation in Linux with the pthread API.
3. inter-process communication using pipes.
Description - Two programs have been provided: user.c and server.c. Your task shall be to complete these two programs such that the execution of the program user creates four processes as follows:
1. User process: this is the original process invoked when user is run. It is responsible for creating the other three processes after which is simulates User that exchanges messages with Bot (simulated by the Bot process).
2. Bot process: this is a child process of the User process that simulates Bot who exchanges messages with User.
3. User Server process: This process (that runs the server program) provides a server service that services the User process. It shall use one thread to read text messages from its standard input which is then send to a communications channel to the Bot process. A second thread is used to send to its standard output any text messages received from the Bot process over a communications channel.
4. Bot Server process: This process (that runs the server program) provides server service that services the Bot process. It shall use one thread to read text messages from its standard input which is then send to a communications channel to the User process. A second thread is used to send any text messages received from the User process over a communications channel to its standard output.
5. Message Flow: User sends the first message and Bot responds with two messages(two options).User selects one and Bot sends Another two options and so on...
The user program is designed to test the server program by simulating a User and a Bot that exchange a sequence of text messages. Four pipes are used as shown below: two pipes allow the User and Bot processes to send messages to the standard inputs of the User Server and Bot Server processes respectively. Two other pipes are used as the communication channel between the Servers. The User process that spawns the Server processes creates the pipes and passes the file descriptors of the communication channel pipes to the server programs.
The pipe identifiers and process identifiers (PIDS) shown in the above diagram are specific to a run and correspond to the identifiers shown in the output of item 4 in the section "Background Information". All standard error file descriptors (2) and the standard outputs of the Server processes are connected to the terminal. The path of messages from Bot process is shown (a similar path is taken for messages from the User process).
To complete the assignment:
1. Start with the provided files user.c and server.c. Complete the documentation in each file to indicate your name and student number. Take the time to document well your code. Consider taking the time to design your code before you start coding.
2. Complete the following functions:
a. user.c: setupBot(),initUserServer(),
initBotServer(),setupUser()
(also complete main to have these functions run properly)
b. server.c: generateThreads()
3. The programs should be compiled using the commands "cc -o user user.c" and "cc -o server server.c -lpthreads" (note that for server compilation, the pthreads library must be explicitly specified). The file makefile has been provided to compile both files - simply type in the command make.
4. To submit the assignment, upload the files user.c and server.c. Do not forget to click on the submit button after (and only after) you have uploaded the file.
5. A word of caution, for debugging the programs, if you wish to write messages to the terminal, you should write to the standard error using the following library call: fprintf(stderr,"message string\n") as the standard input and standard output are to be modified.
6. See point 4 in "Background Information" (attached) for hints on how to observe processes/threads and pipes to help debug your programs.
7. When user is run, the following output should appear on your screen (Note that PIDs shall be specific to your execution).
Note - Just need the codes.
Attachment:- Assignment Files.rar