OS Lab Mid Paper B
OS Lab Mid Paper B
(b) Write a shell script to manage company records. Your script should allow the user to input the
following details for the company using command line arguments (separated by space): Company
name, and Names and Salaries of 3 employees. Once the data is entered, display a menu with the
following options:
1. Calculate the average salary of the company.
2. Display the employee with the highest salary.
3. Sort employees by salary and display the sorted list along with employee name
4. Save employee records to a text file and view the text file.
5. Exit the program.
Upon selecting an option, your script should perform the corresponding operation and display the
result. Ensure that your script handles invalid inputs gracefully and provides appropriate error
messages.
Page 1 of 2
National University of Computer and Emerging Sciences
CLO # 2: Gain hands on experience in writing code that interacts with operating system services
related process and files system, multi-thread programing and different synchronization
primitives. (Lab # 4 and Lab # 6)
Q2. [9.5 marks]
(a) The Collatz conjecture concerns what happens when we take any positive integer n and apply
the following algorithm:
The conjecture states that when this algorithm is continually applied, all positive integers will
eventually reach 1. For example, if n = 35, the sequence is 35, 106, 53, 160, 80, 40, 20, 10, 5,
16, 8, 4, 2, 1. Write a C program using the fork() system call that determines the length of the
Collatz sequence until it reaches 1. The starting number will be provided from the command
line. For example, if 8 is passed as a parameter on the command line, the child process will
output 8, 4, 2, 1. Because the parent and child processes have their own copies of the data. Have
the parent invoke the wait() call to wait for the child process to complete before exiting the
program. Perform necessary error checking to ensure that a positive integer is passed on the
command line.
(b) An echo server echoes back whatever it receives from a client through shared memory, after
reversing each character in the message. For example, if a client sends the server the string
“operating system”, the server will print “metsys gnitarepo”.
CLO # 3: Understand how to configure and customize Linux Kernel for installations, applying
patches and performance optimizations. (Lab # 2)
Q5. [6 marks]
(a) Create a geometric calculator program using three files: main.c, geometry.c, and geometry.h. In
main.c, utilize functions from geometry.c to compute the area and perimeter of basic geometric
shapes like circles, rectangles, and riangles. Develop a straightforward Makefile, for compiling C
source files into object files and a clean rule to remove object files and the executable. In geometry.c,
implement functions for area and perimeter calculations for circles, rectangles, and triangles. Submit
the completed C files, header files, Makefile, and snapshots of the terminal output.
1. Installing dependencies
2. Download Kernel Sources
3. Configure Kernel (Write command for this):
_______________________________________________________
4. Compile Kernel
5. Install Modules (Write command for this):
_______________________________________________________
6. Install New Kernel
7. Update GRUB Configuration
8. Reboot (Write command for this):
_______________________________________________________
9. Verify
Page 2 of 2