0% found this document useful (0 votes)
16 views

Operating system Lab Manual (1 to 4)

The document outlines various lab tasks related to operating systems, including resource monitoring, C++ programming, shell scripting, and system calls. It includes detailed instructions for completing tasks, filling tables with data, and writing scripts for generating multiplication tables and Fibonacci sequences. Additionally, it covers the use of VirtualBox and the creation of files in both Linux and Windows environments.

Uploaded by

mrj83391
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Operating system Lab Manual (1 to 4)

The document outlines various lab tasks related to operating systems, including resource monitoring, C++ programming, shell scripting, and system calls. It includes detailed instructions for completing tasks, filling tables with data, and writing scripts for generating multiplication tables and Fibonacci sequences. Additionally, it covers the use of VirtualBox and the creation of files in both Linux and Windows environments.

Uploaded by

mrj83391
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Hamdard University

Operating
Systems
Semester 4 th

Name:Hafiz Muhammad Abdullah


CMS ID: 2046-2023
Teacher’s Name: Aijaz Ahmed Lagari

Department of Computing
Hamdard Institute of Engineering & Technology,
Hamdard University

Hamdard Institute of Engineering & Technology, Hamdard University


Sharae Madinat Al-Hikmah, Muhammad Bin Qasim Avenue, Karachi 74600,
Pakistan
Lab Session 1
Introduction to Operating System

Lab Task 1(a)

In Resource Monitor Click CPU tab, find mentioned images and fill the following Table – 1:
Table – 1:

S. No Image PID Status Threads CPU Average CPU


1 System 4 Running 132 0 0.20

2 Explorer.exe 6344 Running 55 0 0.13

3 Svchost.exe 5936 Running 7 0 0.05

Lab Task 1(b)


In Resource Monitor Click Memory tab, find mentioned images and fill the following Table-2:
Table – 2:

S. No Image PID Commit Working Set Shareable Private

1 System 4 Running 132 0 0.20

2 Explorer.exe 6344 Running 55 0 0.13

3 Svchost.exe 5936 Running 7 0 0.05

4 Available 9515MB

5 Cached 2592MB
14251MB
6 Total

7 Installed 14366
Physical Memory
8 Hardware Reserved 85MB

9 In Use 4610MB

10 Modified 138MB

11 Standby 2441MB

12 Free 7131MB
Note: As there will be multiple svchost.exe, find with same PID as in Table – 1.

Lab Task 1(c)


After filling above tables, give details of two images / Applications having most of mentioned
attributes:
Table – 3:

S. No Image PID Status Threads CPU CPU Read Write Working Set
%

1 explorer.exe 1234 Running 45 2.5 25% 120 80 50MB

2 svchost.exe 5678 Running 30 1.8 18% 90 60 40MB

Lab Task 2(a)


Compile it by your name and run the following C++ program in CMD window, after running fill
the table – 4:
Table – 4:

S. No Image PID Status Threads CP CPU Read Write Workin


U % g Set

1 Labtask2a.exe 7890 Running 1 0.8 80% 50 30 10 MB

Lab Task 2(b)


Compile by some different name and run the following C++ program in CMD window, after
running fill the Table – 5:

Table – 5:

S. No Image PID Status Threads CP CPU Read Write Workin


U % g Set

1 labtask2b.exe 8912 Running 1 0.1 10% 20 10 5 MB


Lab Task 3
Checklist
1. VirtualBox 6.0.4 r128413 or Higher
2. Oracle VM VirtualBox Extension Pack 6.0.4 r128413
● To check Extension pack, File -> Preferences -> Extensions
3. LUBUNTU1810.ova

Step 1
Import LUBUNTU VM by double clicking or import options in VirtualBox, and start VM

Step 2
Login to VM, User: admin, Password: 123456789 (If required)

Step 3
● Open qps (A Visual Process Manager)
● Process Count is
● Sort Processes by CPU% usage
● Click on Linear radio button
● Fill Table – 6 with the date of 10 processes from top
● For ease take Screen Capture / Screen shot before filling Table-

Table – 6:
S. No PID TTY STAT USER MEM %CPU START TIME COMMAND_LINE

1234 pts/0 R+ admin 5.2 45.0 10:30:45 00:01:23 firefox --new-window


1

5678 tty1 Ss root 3.1 22.5 09:15:12 00:05:45 Xorg -nolisten tcp
2

9101 pts/1 Sl admin 7.8 15.3 10:45:33 00:03:12 qps


3

2468 ? S root 1.2 8.7 08:20:10 00:10:55 [kworker/u4:1]


4
11:05:2 00:00:4
1357 pts/2 R admin 2.5 6.4 python3 script.py
5 1 5

00:02:3
3690 ? S< root 0.8 4.2 07:55:40 [ksoftirqd/0]
6 0

4821 pts/0 S+ admin 4.0 3.9 10:50:11 00:01:15 lxterminal --geometry


7
8 7531 ? I root 0.3 2.1 09:40:22 00:00:1 [kworker/1:0]
0
11:12:0
8642 pts/1 S admin 1.5 1.8 00:00:3 0 nano document.txt
9 5

00:00:0
9753 ? S root 0.6 1.2 08:05:15 [kthreadd]
10 5

Lab Session 2
Boot Loader

Lab Session 3
Introduction to Command Line
Interface
Lab Task 1(a)
Writing a simple BATCH File
1. Open Notepad
2. Type the below given commands
3. Save it as Bat0.bat
4. Open CMD
5. Change your folder where .batfile is saved
6. Execute BATCH file by typing bat0
7. Write the output in Block – 1
Commands for bat0.bat

Block – 1

Lab Task 1(b)

Writing a simple SHELL script

1. Open Terminal
2. Type nano shell0.sh(Nano is a command line test editor)
3. Type the command list in following box
4. Execute file by typing bash shell0.sh
5. Write the output in Block – 2

Commands for shell0.sh


Block –

Lab Task 2
Write a script to generated table of your choice up to 12 counts and save it in a file.
#!/bin/bash

# Define the number for which the multiplication


table will be generated number=5

# Define the file where the table will be saved


output_file="table_$number.txt"

# Remove the file if it already


exists rm -f $output_file

# Generate the multiplication table up to 12 and


save it to the file for i in {1..

12} do result=$((number * i)) echo

"$number x $i = $result" >>

$output_file done

# Notify that the table has been saved echo "Multiplication

table of $number saved in $output_file"


Lab Task 3
Write a script to generate Fibonacci numbers up to a specified count and save them in a file.

#!/bin/bash

# Define the count of Fibonacci numbers to


generate count=12

# Define the file where the Fibonacci numbers will be saved


output_file="fibonacci_numbers.txt"

# Remove the file if it already


exists rm -f $output_file

# Initialize the first two


Fibonacci numbers a=0 b=1

# Add the first Fibonacci number to


the file echo $a >> $output_file

# Generate Fibonacci numbers and save them


to the file for (( i=1; i<$count; i++ ))
do echo $b >> $output_file
# Calculate the next
Fibonacci number temp=$b
b
=
$
(
(
a
+
b
)
)
a = $
t e m
p done

# Notify that the Fibonacci sequence


has been saved echo "Fibonacci sequence
of $count numbers saved in
$output_file"

For understanding:

Let's assume:

● Initially, a=0 and b=1.

After one iteration of the loop:

1. temp=$b → temp=1 (store b into temp).


2. b=$((a + b)) → b=0+1=1 (update b to the next Fibonacci number).
3. a=$temp → a=1 (update a to the previous value of b).

After the second iteration:

● Now a=1 and b=1.

1. temp=$b → temp=1.
2. b=$((a + b)) → b=1+1=2.
3. a=$temp → a=1.

After the third iteration:

● Now a=1 and b=2.

1. temp=$b → temp=2.
2. b=$((a + b)) → b=1+2=3.
3. a=$temp → a=2.

This process continues to generate the Fibonacci numbers.


Lab Session 4
System Calls

Lab Task 1(a)

#include
<stdio.h>
#include
<sys/types
.h>
#include
<sys/stat.
h> #include
<fcntl.h>
#include
<unistd.h>

int main()
{ int fd;

// Create the file with read & write


permission for owner and read only for group and
others fd = creat("/tmp/newfile", 0644);
if (fd < 0) { perror("Error
creating file");
return 1;

printf("File created successfully: /tmp/newfile\


n"); close(fd); // Close the file
descriptor return 0;

Lab Task 1(b)

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main() { int fd; // Open (or create) file with
O_WRONLY | O_CREAT | O_TRUNC
fd = open("/tmp/newfile", O_WRONLY | O_CREAT | O_TRUNC,
0644); if (fd < 0) { perror("Error opening file");
return 1; } printf("File opened/created
successfully: /tmp/newfile\n"); close(fd); return 0; }

Lab Task 1(c)

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h> #include
<fcntl.h> int main()
{ int fd; char
buffer[] = "Hello, World!";
off_t newpos; // Open
file for read-write fd =
open("/tmp/newfile", O_RDWR
| O_CREAT, 0644); if (fd
< 0) { perror("Error
opening file");
return 1; }
// Write to file write(fd, buffer,
sizeof(buffer) - 1); // Move to 16 bytes before
EOF (negative offset) newpos = lseek(fd, -16,
SEEK_END); printf("New position: %ld\n",
newpos); // Append data at the end
lseek(fd, 0, SEEK_END); write(fd, " Appended!",
10); close(fd); return 0; }
Lab Task 2
#include <windows.h>
#include <stdio.h>
int main()
{ STARTUPINFO
si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si)); si.cb
= sizeof(si); ZeroMemory(&pi,
sizeof(pi));
// Launch Notepad
if (!CreateProcess(
NULL, // No module name (use command
line)
"notepad.exe", // Command to execute
NULL, // Process handle not
inheritable NULL, // Thread handle not
inheritable
FALSE, // No handle inheritance
0, // No creation flags
NULL, // Use parent's environment
NULL, // Use parent's directory
&si, // Pointer to STARTUPINFO
&pi // Pointer to
PROCESS_INFORMATION )) { printf("CreateProcess
failed (%d).\n", GetLastError()); return 1; }
printf("Notepad launched with PID: %d\n", pi.dwProcessId);
CloseHandle(pi.hProcess); CloseHandle(pi.hThread);
return 0; }

You might also like