Operating system Lab Manual (1 to 4)
Operating system Lab Manual (1 to 4)
Hamdard University
Operating
Systems
Semester 4 th
Department of Computing
Hamdard Institute of Engineering & Technology,
Hamdard University
In Resource Monitor Click CPU tab, find mentioned images and fill the following Table – 1:
Table – 1:
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.
S. No Image PID Status Threads CPU CPU Read Write Working Set
%
Table – 5:
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
5678 tty1 Ss root 3.1 22.5 09:15:12 00:05:45 Xorg -nolisten tcp
2
00:02:3
3690 ? S< root 0.8 4.2 07:55:40 [ksoftirqd/0]
6 0
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
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
Lab Task 2
Write a script to generated table of your choice up to 12 counts and save it in a file.
#!/bin/bash
$output_file done
#!/bin/bash
For understanding:
Let's assume:
1. temp=$b → temp=1.
2. b=$((a + b)) → b=1+1=2.
3. a=$temp → a=1.
1. temp=$b → temp=2.
2. b=$((a + b)) → b=1+2=3.
3. a=$temp → a=2.
#include
<stdio.h>
#include
<sys/types
.h>
#include
<sys/stat.
h> #include
<fcntl.h>
#include
<unistd.h>
int main()
{ int fd;
#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; }
#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; }