Operating_System_Lab_BCS451
Operating_System_Lab_BCS451
Details:
UNIX/Linux:
o uname -a
Output:
Command Explanation:
#include <unistd.h>
int main() {
char hostname[1024];
gethostname(hostname, 1024);
return 0;
o ./system_info
Output:
o Windows XP/7/8:
o Syntax: systeminfo
o Description: Displays detailed configuration
information about the computer and its operating
system
o Output:
o Host Name: MYPC
Code (C):
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
if (pid == 0) {
printf("Child process\n");
} else {
wait(NULL);
printf("Parent process\n");
return 0;
Input:
gcc process.c -o process
./process
Output:
Child process
a.out
file1.txt
file2.c
Parent process
Code (C):
#include <fcntl.h>
#include <unistd.h>
int main() {
close(fd);
return 0;
}
Input:
gcc process.c -o process
./process
Output:
Child process
Parent process
Code (C):
#include <unistd.h>
int main() {
char buffer[100];
return 0;
Input:
Hello, this is a test.
Output:
Hello, this is a test.
3. Implement CPU Scheduling Policies
i. Shortest Job First (SJF)
Algorithm:
Sort processes by burst time.
Code (C):
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &bt[i]);
p[i] = i+1;
wt[0] = 0;
printf("\nProcess\tBT\tWT\tTAT\n");
return 0;
Input:
Enter the number of processes: 3
Output:
Process BT WT TAT
P2 2 0 2
P3 4 2 6
P1 6 6 12
Code (C):
#include <stdio.h>
struct Process {
int pid;
int bt;
int priority;
int wt;
int tat;
};
temp = p[i];
p[i] = p[j];
p[j] = temp;
int main() {
int n;
scanf("%d", &n);
p[i].pid = i + 1;
sortByPriority(p, n);
p[0].wt = 0;
p[0].tat = p[0].bt;
printf("\nProcess\tBT\tPriority\tWT\tTAT\n");
return 0;
Input:
Enter the number of processes: 3
Output:
Process BT Priority WT TAT
P2 3 1 0 3
P1 5 2 3 8
P3 8 3 8 16
Code (C):
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &bt[i]);
wt[0] = 0;
printf("\nProcess\tBT\tWT\tTAT\n");
return 0;
Input:
Enter the number of processes: 3
Output:
Process BT WT TAT
P1 5 0 5
P2 3 5 8
P3 2 8 10
Implementation Hint:
CODE(C):
#include <stdio.h>
#include <string.h>
typedef struct {
int pid;
int arrival_time;
int burst_time;
int remaining_time;
int completion_time;
char queue_type[10];
} Process;
*current_time = sys[i].arrival_time;
*current_time += sys[i].burst_time;
sys[i].completion_time = *current_time;
int executed = 0;
time += user[i].remaining_time;
user[i].remaining_time = 0;
user[i].completion_time = time;
finished[i] = 1;
remaining--;
} else {
time += quantum;
user[i].remaining_time -= quantum;
executed = 1;
if (!executed) {
time++;
int main() {
Process processes[MAX], system_queue[MAX], user_queue[MAX];
int quantum;
scanf("%d", &n);
processes[i].pid = i + 1;
scanf("%d", &processes[i].arrival_time);
scanf("%d", &processes[i].burst_time);
scanf("%s", processes[i].queue_type);
processes[i].remaining_time = processes[i].burst_time;
if (strcmp(processes[i].queue_type, "system") == 0) {
system_queue[sys_count++] = processes[i];
} else {
user_queue[user_count++] = processes[i];
}
scanf("%d", &quantum);
int current_time = 0;
printf("\nCompletion Times:\n");
processes[system_queue[i].pid - 1].completion_time =
system_queue[i].completion_time;
processes[user_queue[i].pid - 1].completion_time =
user_queue[i].completion_time;
return 0;
Input:
Enter number of processes: 5
Process 1:
Arrival Time: 0
Burst Time: 4
Process 2:
Arrival Time: 1
Burst Time: 3
Process 3:
Arrival Time: 2
Burst Time: 5
Queue Type (system/user): user
Process 4:
Arrival Time: 3
Burst Time: 4
Process 5:
Arrival Time: 4
Burst Time: 2
Output:
System Queue Execution (FCFS):
Completion Times: