0% found this document useful (0 votes)
15 views45 pages

Smit Donga C4 Finallll - OS

The document outlines practical exercises related to the study of Linux/UNIX commands and shell scripting for a computer engineering course. It covers basic and advanced commands, file permissions, and practical tasks such as generating a student marksheet and calculating factorials. The document serves as a comprehensive guide for students to understand and apply various Linux commands and scripting techniques.

Uploaded by

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

Smit Donga C4 Finallll - OS

The document outlines practical exercises related to the study of Linux/UNIX commands and shell scripting for a computer engineering course. It covers basic and advanced commands, file permissions, and practical tasks such as generating a student marksheet and calculating factorials. The document serves as a comprehensive guide for students to understand and apply various Linux commands and scripting techniques.

Uploaded by

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

A D PATEL INSTITUTE OF TECHNOLOGY

DEPT. OF COMPUTER ENGINEERING


Operating System (202040402)

Name: Donga Smit Jashvantkumar


Branch: Computer Engineering
Enrolment No.: 12302040601053
Batch: C4
Subject: Operating Systems (202040402)
Semester: 4th semester

1
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical – 1
Study of Basic commands of Linux/UNIX:

Linux:

Linux is an open-source, Unix-like operating system kernel created by Linus Torvalds in 1991.
It forms the backbone of numerous Linux distributions, such as Ubuntu, Fedora, and Debian.
Known for its robustness, flexibility, and security, Linux is widely used in various fields,
including servers, desktops, embedded systems, and cloud computing.

With support for multitasking and multi-user functionality, Linux operates on a wide range
of hardware, from small IoT devices to powerful supercomputers. Its open-source nature
allows developers and users to modify and tailor the system to their specific needs, making
it a reliable and versatile choice for both personal and enterprise use.

About terminal:
Terminal:
1. A terminal is a command-line interface that allows users to interact with the
operating system using text-based commands.
2. It provides a way to execute programs, manage files, and automate tasks on Unix-
like systems.
BonTerminal:
1. BonTerminal is a simple and lightweight terminal emulator for Linux-based systems.
2. It focuses on providing a minimalistic, fast, and user-friendly experience for terminal-
based tasks.
Bash:
1. Bash (Bourne Again Shell) is a popular Unix shell and command language used for
interacting with the system.
2. It supports scripting, job control, and provides powerful features for automating
tasks and managing the system.

Directory commands:
Directory commands are commands that deals with all the directories.

⮚ ls command:
ls command is used to list out all the files present in the directory

Usage:
ls –[OPTIONS] [FILE]

Options:
-a, --all do not ignore entries starting with .
2
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

-l use a long listing format


-r, --reverse reverse order while sorting
-t sort by time, newest first; see –time
-R, --recursive list subdirectories recursively
-p append / indicator to directories
-s, --size print the allocated size of each file, in blocks
-f do not sort, enable -aU, disable -ls –color
-F append indicator (one of */=>@|) to entries
-h with -l and -s, print sizes like 1K 234M 2G etc.

Examples:

3
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

mkdir command:
mkdir command is used create a new directory

Usage:
mkdir –[OPTIONS] [DIRECTORY NAME]

Options:
-p no error if existing, make parent directories as needed

4
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Examples:

⮚ rmdir command:
rmdir command is used to remove directory.

Usage:
rmdir –[OPTIONS] [DIRECTORY]

Options:
-p remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
similar to 'rmdir a/b/c a/b a'

Examples:

5
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

⮚ cd command
cd command is used to change directory

Usage:
cd [DIRECTORY PATH]

Options:
(None commonly used with this command; it simply takes a directory path as an
argument.)

Examples:

⮚ pwd command
pwd command is used to know present working directory

Usage:
pwd -[OPTIONS]

6
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Options:
(None commonly used with this command; it simply takes a directory path as an
argument.)

Examples:

Filesystem commands:
Filesystem commands are used to manage, manipulate, and interact with files and
directories, including operations like creating, deleting, and modifying them.

⮚ cat command
cat command is used to see content inside the file.

Usage:
cat -[OPTIONS] [FILE NAME]

Options:
(None commonly used with this command; it simply takes a directory path as an
argument.)

Examples:

⮚ rm command
rm command is used to remove files or directories.

7
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Usage:
rm –[OPTIONS] [FILE NAME]

Options:
-r remove directories and their contents recursively
-f ignore non-existent files and arguments, never prompt
-i prompt before every removal

Examples:

⮚ touch command
touch command is used to create file.

Usage:
touch –[OPTIONS] [FILENAME]

Options:
-a change only the access time
-c do not create any files

Examples:

8
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

⮚ find command
find command is used to search for files in a directory hierarchy

Usage:
find –[OPTIONS] [FILENAME] –[ACTOIN]

Options:
-print display matching files or directories
-exec execute a command on matching files
-name search for files or directories by name
-user search for files owned by a user
-type search by file type (f: files, d: directories)
-size +n or -n search files by size (+n: larger, -n: smaller, n: exact)
-"a*.txt" and a*.txt search files starting with a and ending with .txt
-mtime +n or n or -n search files by modification time (+n: older,
-n :recent, n: exact days)
-mmin +n or n or -n search files by modification time in minutes
-atime +n or n or -n search files by access time

Examples:

9
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

⮚ cp command:
cp command is used to copy files and directories.

Usage:
cp –[OPTIONS] [FILENAME] [PATH TO COPY]

Options:
-i overwrite files without prompting
-r copy directories recursively
-u copy only when the source file is newer than the destination
file or when the destination file is missing
-v verbose mode, show files being copied
-f force overwrite without prompting
-a preserve file attributes while copying
Examples:

10
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

⮚ mv command:
mv command is used to move or rename files and directories.

Usage:
mv –[OPTIONS] [FILENAME] [NEWNAME]

Options:
(None commonly used with this command; it simply takes a directory path as an
argument.)

Examples:

⮚ wc command:
wc command is used to count lines, words, and bytes in a file.
11
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Usage:
wc -[OPTIONS] [FILENAME]

Options:
-l count lines in a file
-w count words in a file
-c count characters in a file

Examples:

⮚ file command:
file command is used to determine the file type.

Usage:
File –[OPTIONS] [FILENAME]

Options:
* match all files

12
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Examples:

⮚ cmp command:
cmp command is used to compare two files byte by byte.

Usage:
cmp –[OPTIONS] [FILE1] [FILE2]

Options:
(None commonly used with this command; it simply takes a directory path as an
argument.)
Examples:

⮚ comm command:
comm command is used to compare two sorted files line by line.

Usage:
Comm –[OPTIONS] [FILE1] [FILE2]

Options:
13
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

-1 suppress lines unique to the first file


-2 suppress lines unique to the second file
-3 suppress lines that appear in both files

Examples:

14
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 2
Study of Advance commands and filters of Linux/UNIX.
File Permissions Overview:
File permissions in Linux are represented in a format like -rwxrw-r—. This format helps in
understanding how a file or directory is accessible by different users.
● -: Indicates a regular file (If it's d, it means a directory).
● rwx: Permissions for the user (owner of the file).
○ r (read): Permission to read the file.
○ w (write): Permission to modify the file.
○ x (execute): Permission to run the file as a program.
● rwx: Permissions for the group (users in the same group as the file).
○ r (read): Permission to read the file.
○ w (write): Permission to modify the file.
○ x (execute): Permission to run the file as a program.
● r--: Permissions for others (all other users on the system).
○ r (read): Permission to read the file.
○ - (write/execute): No write or execute permission.

Common Commands for Managing File Permissions:

Ø chmod command:
chmod command is used to change the permissions of a file or directory.

Usage:
chmod [user-symbolset<set/deny symbol>] accesssymbol filename

Examples:

This adds the execute permission (`x`) for the user (`u`) on the file

Octal Notations:
· 0: No permission.
15
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

· 4: Read permission.
· 2: Write permission.
· 1: Execute permission.
· Combine values for multiple permissions:
o chmod 333 file.txt gives read (r), write (w), and execute (x) permission to
user, group, and others.

Ø touch command:
touch command is used to create an empty file or update the access and
modification timestamps of an existing file.

Usage:
touch MMDDHHmm filename

Example:

Ø dd command:
dd command is used for low-level copying and conversion of files.

16
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Usage:
dd if=source_file of=destination_file conv=lcase/ucase/ascii/ebcdic
Example:

Ø tail command:
tail command is used to display the last few lines of a file.

Usage:
tail +n filename

Example:

17
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

grep - Search for Patterns


o Syntax: grep [options] "pattern" [file]

o Description: Searches for lines containing a specified pattern.

o Terminal View:

sort -r - Sort Lines in Reverse


o Syntax: sort -r [file]

o Description: Sorts lines in reverse order.

o Terminal View:

18
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

1. uniq -c - Count Duplicate Lines


o Syntax: uniq -c [file]

o Description: Counts occurrences of duplicate lines in a sorted file.

o Terminal View:

19
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

1. cut - Extract Sections from Lines


o Syntax: cut [options] [file]

o Description: Extracts specific sections (e.g., characters, fields)


from lines.
o Terminal View:

ubuntu@ubuntu:~/lab$ echo -e "John,Doe,30\nJane,Smith,25" > users.txt


ubuntu@ubuntu:~/lab$ cut -d',' -f1 users.txt
John
Jane

o Explanation: Extracts the first field (names) from users.txt using ,


as the delimiter.
2. wc - Word, Line, and Character Count
o Syntax: wc [options] [file]

o Description: Counts lines, words, and characters in a file.

o Terminal View:
o

ubuntu@ubuntu:~/lab$ wc notes.txt
3 12 85 notes.txt

20
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 3: Write a Shell Script to


Generate a Student Marksheet
Objective
Create a shell script to collect a student’s name, roll number, and marks in five
subjects (expanded from three), calculate total marks, percentage, and class,
and display a detailed marksheet.

Sample Execution and Output:

21
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Explanation
● Collects input for five subjects instead of three for a more comprehensive
marksheet.
● Uses bc for precise percentage calculation with two decimal places.

● Assigns class based on percentage thresholds and displays a detailed,


formatted marksheet.

22
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 4: Write a Shell Script to


Display Multiplication Table
Objective
Develop a shell script to take a number and a range as input, then display its
multiplication table up to the specified range (expanded from a fixed 10).
Script

Sample Execution and Output

Explanation
● Takes a number and a custom range as input.

● Validates the range; defaults to 10 if invalid.Uses printf for aligned output,


showing the table up to the specified range.

23
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 5: Write a Shell Script to Find


Factorial of Given Number n
Aim
To create a shell script that calculates the factorial of a user-provided positive
integer n, where factorial (n!) is the product of all positive integers from 1 to n
(e.g., 5! = 5 × 4 × 3 × 2 × 1 = 120), and displays the result with appropriate
validation.
Shell Script

Terminal Output

24
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Detailed Explanation
● Shebang (#!/bin/bash): Specifies that this is a Bash script, ensuring it
runs in the Bash shell.
● Header: Prints a decorative header to make the script user-friendly and
indicate its purpose.
● Input Prompt: Asks the user to enter a number and stores it in the
variable n using read.
● Validation:

o [[ "$n" =~ ^[0-9]+$ ]] checks if n contains only digits (no letters or


special characters).
o [ "$n" -lt 0 ] ensures the number isn’t negative, as factorial isn’t
defined for negative numbers.
o If invalid, an error message is displayed, and the script exits with
status 1.
● Initialization: Sets factorial to 1, the starting point for multiplication.

● Loop: Iterates from 1 to n, multiplying factorial by each integer i and


showing each step for clarity.
● Output: Displays the final factorial with a formatted message, enclosed in
decorative lines.

25
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 6: Write a Menu-Driven Shell


Script for Various Tasks
Aim
To develop a menu-driven shell script that offers five options and performs the
following tasks based on user selection:
● a. Display the calendar of the current month.

● b. Show the current date and time.

● c. List usernames of users currently logged into the system.

● d. Print the user’s name at a specified (x, y) terminal position.

● e. Display the user’s terminal device number.

Shell Script:

26
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Terminal Output:

Detailed Explanation
● Shebang (#!/bin/bash): Ensures the script runs in Bash.

● Menu Display: Uses multiple echo commands to create a formatted


menu with clear options and decorative lines.
● Input: Reads the user’s choice into choice.

● Case Statement: Handles each option:

o a: cal displays the current month’s calendar (e.g., April 2025).

o b: date shows the current date and time (e.g., Fri Apr 4 14:30:00
UTC 2025).
o c: who lists logged-in users with their terminal, login time, and IP (if
remote).

27
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

o d: Prompts for a name and (x, y) coordinates, validates them as


non-negative integers, and uses tput cup to position the cursor
before printing the name.
o e: tty outputs the terminal device (e.g., /dev/pts/0).

o Default (*): Handles invalid inputs with an error message.

● Formatting: Each option’s output is framed with lines for readability

28
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 7: Write a Shell Script to Read


Aim:-To create a shell script that reads a piece of data (e.g., a number or text)
from the user, performs basic validation, and displays it back with a confirmation
message. Since the aim was incomplete, this assumes a simple read-and-display
task with added descriptiveness.
Shell Script

Terminal Output

Detailed Explanation
● Shebang (#!/bin/bash): Specifies the Bash shell for execution.

Header: Prints a formatted title and description to explain the script’s


purpose.
Input Prompt: Asks the user to enter data (number or text) and stores it
in input using read.
Validation: Uses [ -z "$input" ] to check if the input is empty; if so, it
displays an error and exits with status 1.
Output: Echoes the input back to the user with a confirmation message,
surrounded by decorative lines for clarity

29
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 8: Shell Programming Using


Filters (including grep, egrep, fgrep)
Aim
To write a shell script that demonstrates the use of filters like grep, egrep, and
fgrep to process text data, such as searching for patterns in a file, with examples
of their distinct functionalities.

Shell Script:

Terminal Output

30
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Detailed Explanation
● Shebang (#!/bin/bash): Runs the script in Bash.

● Header: Introduces the script’s purpose with a formatted title.

● Sample File: Creates data.txt with varied content to demonstrate


filtering.
● Filters:

o grep: Searches for "hello" (case-sensitive), finding only exact


matches.
o grep -i: Searches case-insensitively, finding all variations of "hello".

o egrep: Uses extended regex to match "Linux" or "World" with the |


operator.
o fgrep: Searches for the exact string "hello123" without interpreting
it as a regex.
● Cleanup: Removes the temporary file to keep the directory tidy.

● Output: Each filter’s result is displayed with descriptive labels and


separators.

31
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 9: Write a Shell Script to Read


n Numbers as Command Arguments
and Sort Them in Descending Order
Aim
To create a shell script that accepts n numbers as command-line arguments,
sorts them in descending order, and displays the result, with validation for
proper input.

Shell Script

Terminal Output

Detailed Explanation
● Shebang (#!/bin/bash): Specifies Bash as the interpreter.

● Header: Displays a title and purpose.

● Input Check: Uses $# to verify if arguments exist; if not, shows usage


and exits.
● Validation: Loops through each argument ("$@") to ensure it’s a positive
integer using regex.

32
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

● Array: Stores arguments in numbers for display.

● Sorting: Converts the array to a newline-separated list with tr, then uses
sort -nr (n for numeric, r for reverse) to sort in descending order.
● Output: Shows the original numbers and the sorted result with
formatting.

Practical 10: Write a Shell Script to


Display All Executable Files,

33
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Directories, and Zero-Sized Files from


Current Directory

Aim
To develop a shell script that lists all executable files, directories, and zero-sized
files in the current directory, categorizing and displaying them separately.

Shell Script

Ouptut

Detailed Explanation
● Shebang (#!/bin/bash): Runs in Bash.

● Header: Shows the script’s purpose and current directory path with pwd.

34
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

● Executable Files: find . -maxdepth 1 -type f -executable finds files (-type


f) that are executable, lists them with ls -l, and checks if any exist.
● Directories: find . -maxdepth 1 -type d -not -path . finds directories (-type
d), excludes the current directory (.), and lists them.
● Zero-Sized Files: find . -maxdepth 1 -type f -size 0 finds files with zero
bytes and lists them.
● Conditional Output: If no matches are found in any category, "None
found" is displayed using -z to test emptiness.
● Formatting: Each category is separated by lines for clarity.

Practical 11: Write a Shell Script to


Check if Entered String is a Palindrome
or Not
Aim

35
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

To create a shell script that reads a string from the user and determines whether
it is a palindrome (reads the same forward and backward, e.g., "radar") by
reversing it and comparing.

Shell Script

Output:

Detailed Explanation
● Shebang (#!/bin/bash): Specifies Bash execution.

● Header: Introduces the script with a formatted title and purpose.

● Input: Reads a string into input.

● Cleaning: tr -d ' ' removes spaces, and tr '[:upper:]' '[:lower:]' converts to


lowercase to handle cases like "Race Car".
● Reversing: rev reverses the cleaned string.

● Comparison: Uses an if statement to check if the cleaned string equals


its reverse.
● Output: Displays the cleaned input, reversed string, and result, with
separators for readability.

36
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 12: Write a Shell Script to


Validate the Entered Date (Format: dd-
mm-yyyy)
Aim
To create a shell script that validates a user-entered date in the format dd-mm-
yyyy, ensuring it adheres to rules such as valid day (01-31), month (01-12), year
(positive), and leap year logic for February.

Shell Script

37
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Terminal Output

Detailed Explanation

38
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

● Shebang: Runs in Bash.

● Header: Introduces the script’s purpose.

● Input: Reads a date string.

● Format Check: Uses regex to ensure dd-mm-yyyy format (e.g., 01-12-


2023).
● Splitting: Uses IFS='-' to split into day, month, and year.

● Validation:

o Checks month (01-12), day (01-31), and year (>0).

o Adjusts max days for April, June, September, November (30 days).

o For February, calculates leap year (divisible by 4, not 100 unless


400) and sets 28 or 29 days.
● Output: Confirms validity or shows specific errors with context.

Practical 13: Write an Awk Program


Using Function to Convert Each Word in
a Given Text into Capital
Aim
To write an awk program with a function that capitalizes each word in a text
input, demonstrating awk’s text-processing capabilities.

Awk Script
Awk Script
#!/usr/bin/awk -f
# This awk script capitalizes each word in the input text.
BEGIN {
print "========================================="

39
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

print " Word Capitalizer"


print "========================================="
print "Enter text (press Ctrl+D when done):"
}

# Define function to capitalize a word


function capitalize(word) {
return toupper(substr(word, 1, 1)) tolower(substr(word, 2))
}

# Process each line


{
print "Original line: " $0
printf "Capitalized: "
for (i = 1; i <= NF; i++) {
printf "%s ", capitalize($i)
}
print "" # Newline after each line
}

END {
print "========================================="
}

Terminal Output

ubuntu@ubuntu:~/scripts$ chmod +x capitalize.awk


ubuntu@ubuntu:~/scripts$ ./capitalize.awk
=========================================
Word Capitalizer
=========================================
Enter text (press Ctrl+D when done):
hello world linux
Original line: hello world linux
Capitalized: Hello World Linux
this is a TEST
Original line: this is a TEST
Capitalized: This Is A Test
^D
=========================================

Detailed Explanation
● Shebang: Runs with awk -f to interpret the script.

● Header: Prints a title in the BEGIN block.

● Function: capitalize takes a word, uppercases the first letter (toupper),


lowercases the rest (tolower), and concatenates them.
● Main Logic: Loops through each field (NF = number of fields) in a line,
applies capitalize, and prints with spaces.
● Output: Shows original and capitalized versions of each line, ending with
a footer.

40
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Practical 14: Write a Program to


Demonstrate fork, join, exec, and wait
System Calls

Aim
To write a C program that demonstrates the use of fork (create a child process),
exec (replace process image), wait (synchronize parent and child), and implicitly
join processes.

C Program

#include <stdio.h>
#include <unistd.h>

41
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

#include <sys/wait.h>
#include <stdlib.h>

int main() {
pid_t pid;
printf("=========================================\n");
printf(" Process Demonstration\n");
printf("=========================================\n");
printf("Parent process starting (PID: %d)\n", getpid());

// Fork a child process


pid = fork();

if (pid < 0) {
// Fork failed
printf("Error: Fork failed!\n");
exit(1);
} else if (pid == 0) {
// Child process
printf("Child process created (PID: %d, Parent PID: %d)\n", getpid(),
getppid());
printf("Child executing 'ls -l' using exec...\n");
execlp("ls", "ls", "-l", NULL); // Replace child with ls -l
printf("Error: exec failed!\n"); // This won’t run if exec succeeds
exit(1);
} else {
// Parent process
printf("Parent (PID: %d) waiting for child (PID: %d) to finish...\n",
getpid(), pid);
wait(NULL); // Wait for child to complete
printf("Child process completed. Parent resuming.\n");
printf("----------------------------------------\n");
}

printf("=========================================\n");
return 0;
}

Terminal Output

ubuntu@ubuntu:~/scripts$ gcc -o process_demo process_demo.c


ubuntu@ubuntu:~/scripts$ ./process_demo
=========================================
Process Demonstration
=========================================
Parent process starting (PID: 12345)
Parent (PID: 12345) waiting for child (PID: 12346) to finish...
Child process created (PID: 12346, Parent PID: 12345)
Child executing 'ls -l' using exec...
dir1 file1.txt file2.txt script.sh (simulated ls -l output)
Child process completed. Parent resuming.
----------------------------------------
=========================================

42
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Detailed Explanation
● Header: Displays program purpose.

● Fork: Creates a child process; pid is 0 in child, child’s PID in parent.

● Child: Uses execlp to replace its image with ls -l; if it fails, prints an error.

● Parent: Uses wait to pause until the child finishes, simulating a join.

● Output: Shows process IDs and execution flow, with ls -l output as an


example (actual output depends on directory contents).

Practical 15: Write a C program to


stimulate FCFS CPU Scheduling
Algorithm
Aim:-
To write a C program that stimulates the FCFS CPU scheduling
algorithm,Calculating waiting and turn-around times for processes based on their
arrival and burst times.
C program:-

43
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Terminal Output

44
Operating system (202040402) CP Vansh Lunagariya(12302040601061)

Detailed Explanation

 Header: Introduces the FCFS simulation.


 Input: Reads number of processes and their burst times.
 Calculation:
o First process: wait[0] = 0, turnaround[0] = burst[0].
o Subsequent processes: wait[i] = wait[i-1] + burst[i-1],
turnaround[i] = wait[i] + burst[i].
 Output: Displays a table with process details and computes
average waiting and turnaround times.
 Assumption: Arrival time is 0 for all processes (simplified FCFS).

45

You might also like