0% found this document useful (0 votes)
3 views16 pages

DOS - Assignment 2, 3, 4, University Based

The document outlines a series of laboratory assignments focused on the design of operating systems, primarily involving the creation of shell scripts and C programs. Tasks include merging file contents, displaying system information, performing arithmetic operations, and process management using fork(). Each assignment requires the scripts to be executable and run as commands, emphasizing practical application of operating system concepts.

Uploaded by

mardiblbiswajit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

DOS - Assignment 2, 3, 4, University Based

The document outlines a series of laboratory assignments focused on the design of operating systems, primarily involving the creation of shell scripts and C programs. Tasks include merging file contents, displaying system information, performing arithmetic operations, and process management using fork(). Each assignment requires the scripts to be executable and run as commands, emphasizing practical application of operating system concepts.

Uploaded by

mardiblbiswajit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Laboratory Assignment 2 Subject: Design of Operating Systems

1. Write a shell script named as prog for merge the content of files a.txt, b.txt, and c.txt sort
them and save the result in a file called result and display the sorted output on the screen.
(Note: a.txt, b.txt and c.txt file contain some numerical value. Make the script an
executable file and run it as a command using its name only.)

2. Write a shell script named as systeminfo that will display the information about the
login name of the user, name of the Unix system used by the user, type of the SHELL, Path
of current working directory of the user and list of files contained in current working
directory. (Make the script an executable file and run it as a command using its name
only.)
3. Write a shell script named as dtcal for displaying both the system date and calendar for
specific month, say march 2022, in the given format:- Date : specific date Calender :
current calendar (Make the script an executable file and run it as a command using its
name only.)

4. Write a shell script named as nvwc which will display the filename and linecount,
wordcount and char count of the file dtcal in the following format: Filename: dtcal Line
count: - Word count: - Charcout: - (Make the script an executable file and run it as a
command using its name only.)

5. Write a shell script named as nvwc2 which will display the filename and line count, word
count and char count of any file given as argument to nvwc2 in the following format:
filename line count word count charcount file1 - - - (Make the script an executable file
and run it as a command using its name only.)
6. Write a shell script named as darg to display the total number of command line
arguments along with the first two arguments. -Modify the script to display all the
arguments. (Make the script an executable file and run it as a command using its name
only.)

7. Write a shell script named as ndisp that will take three command line arguments
specifying the value of n, m and a filename and display the first n number of lines and last
m number of lines of the file given as argument. (Make the script an executable file and
run it as a command using its name only.)
Laboratory Assignments 3 Subject: Design of Operating Systems

1. Write a shell script iaop to perform integer arithmetic on two numbers, where
the value of the two numbers will be given during runtime.

2. Write a shell script faop to perform floating point arithmetic on two numbers,
where the value of the two numbers will be given during runtime.

3. Ramesh’s basic salary is input through the keyboard. His dearness allowance is
40% of basic salary, and house rent allowance is 20% of basic salary. Write a
program to calculate his gross salary.
4. If a five digit number is input given through the keyboard during runtime, write a
program to calculate the sum of its digits.

5. If the cost price and selling price of an item is input through the keyboard, write
a program to determine whether the seller has made profit or incurred loss. Also
determine how much profit was made or loss incurred.

6. Write a shell script which receives any year from the keyboard and determines,
whether the year is a leap year or not. If no argument is supplied the current year
should be assumed.
7. Write a shell script that will display a message to enter internal mark and
percentage in attendance, if the entered mark is greater than equal to 20 and
entered percentage in attendance is greater than equal to 75 then display the
message Allowed for Semester otherwise display the message Not allowed.

8. Write a shell script small3 that will compare three numbers passed as
command line arguments and display the smallest one.

9. Write a shell script check_char which will display one message to enter a
character and according to the character entered it will display appropriate
message from the following options:
● You entered a lower case alphabet
● You entered an upper case alphabet.
● You have entered a digit.
● You have entered a special symbol.
● You have entered more than one character.
10. Write a shell script class_time which will display one message to enter a day
and according to the day entered it will display the DOS class time along with the
room information or the message “No class on day_name” or “Holiday” for
Sunday.

11. Write a shell script filechk that will take two file names as command line
arguments, and check whether the content of two files are the same or not . If the
contents of two files are the same, then it will display the message: Files filename1
and filename2 have the same content. then delete the second file and display the
message: So filename2 is deleted. Otherwise display the message: Files filename1
and filename2 have different content.

12. Write a shell script calculator that will take three command line arguments,
where the first argument will specify the first operand, second argument will
specify the operator and the third argument will specify the second operand and
display the output of the arithmetic operation specified in the following format:
op1 operator op2 = result . If the arguments will be passed in any other sequence,
it will display the message: “Invalid input “ Enter input in following format: op1
operator op2 The symbols to be used for different operators are as follows:
● Addition: + Subtraction: -
● Multiplication: x Division: /
● Modulo: % Exponent: ^
Laboratory Assignments 4 : Design of Operating Systems

1. Write a C program to create a child process using fork() system call. The child
process will print the message “Child” with its process identifier and then continue
in an indefinite loop. The parent process will print the message “Parent” with its
process identifier and then continue in an indefinite loop.
A. Run the program and trace the state of both processes.
B. Terminate the child process. Then trace the state of processes.
C. Run the program and trace the state of both processes. Terminate the
parent process. Then trace the state of processes.
D. Modify the program so that the parent process after displaying the
message will wait for the child process to complete its task. Again run the
program and trace the state of both processes.
E. Terminate the child process. Then trace the state of processes

Solution:

Initial C Program:

A. Run the Program:

B. Kill the child Process and check the state of the child process
C. Start the program and check the state of the processes

D. Modified Program:

E. Kill the child process and check the status


Answers
I. 123 J. 13 M. 66 N. Child: 5 Parent: 6 O. 4 P. 6 Q. 67 R. 4 S. 1 T. 1111
K. Child n=20 Parent n=10 L. Child n=20 Parent n=20

3. Write a C program that will create three child processes to perform the
following operations respectively:
● First child will copy the content of file1 to file2 - Second child will display the
content of file2
● Third child will display the sorted content of file2 in reverse order.
● Each child process being created will display its id and its parent process id
with appropriate messages.
● The parent process will be delayed for 1 second after creation of each child
process. It will display an appropriate message with its id after completion
of all the child processes.
C Program:

4. Write a C program that will create a child process to generate a Fibonacci


series of specified length and store it in an array. The parent process will wait for
the child to complete its task and then display the Fibonacci series and then
display the prime Fibonacci number in the series along with its position with
appropriate message.

You might also like