I have attached the Lab referenced in this description. Please look at the notes and hints as requirements.
Q1: Fork Game
Write a C program that will start a race between 4 processes to get a number from the user inputs. The user will enter 4 numbers (1 to 4), the process that receives the first number (1) will be the winner and in the first place, processes afterward will get second, third and fourth place depending on the number they get from the user.
The program will start by using the fork() System call to create 4 processes, each process created is identified by a number from 1 to 4, this number indicates its creation sequence. For example, the first child process created get ID = 1.
After all, processes are created, the processes will start to request a number from the user. Each process will print the number it got from the user and also print its ID number. The parent does not participate in the race and waits for all child process to finish before it exits.
Notice: The numbers and the order of processes on your computer might be different.
Sample Output
Submission:
- Submit one file named “ForkGame.c”
Q2: Signals
Write a program that will administer a test for users. The questions and answers for the test are written in two separate files. The program will display a question to the user and accept user answers. The test will compare user input to answers. If the answer is correct, the program will add the corresponding points to the Total points for the user.
- The program keeps track of the total amount of time the user has been taking the test vs. time remaining.
- The program also displays a notification every minute to inform the user of time passed vs. time remaining.
- The program does not store any points, questions, or answers. All information is stored in files.
- The program terminates the Exam when time runs out and displays the total points earned.
- The program uses signals and signal handling to keep time.
Files:
- Questions_Exam
- The first line is the total amount of minutes for this test.
- Each line contains a question.
- No space between lines.
- Sample:
10″How many states in the U.S.A ?””How many legs a cat has?””What is the best school in Erie ?””Who is the Tesla of our era ?” - Answers_Exam
- Each line contains the answer to the corresponding question in the Questions_Exam file and how much points this question is worth.
- The two fields are separated by a space.
- No space between lines.
- Sample:
50 1 4 1PSU 10Elon 100 Notes and hints:
- You will need to learn/know how to open and read the file in C
- Functions you might need: fopen , fscanf and fclose.
- Alarm system call, Review Signal Lab.
- Signals Handling function
Sample Output:
Submission:
- One file named “Exam.c”


0 comments