0% found this document useful (0 votes)
8 views8 pages

S.No Name of The Experiments NO. Date Status: Index

lab programs

Uploaded by

krishkiran2408
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)
8 views8 pages

S.No Name of The Experiments NO. Date Status: Index

lab programs

Uploaded by

krishkiran2408
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/ 8

Index

S.NO NAME OF THE EXPERIMENTS PAGE DATE STATUS


NO.

1
Process System Calls
2
IO System Calls
3
IPC using Pipe Processing
4
First Come First Serve Scheduling
5
Shortest job first Scheduling
6
Priority Scheduling
7
Round Robin Scheduling
Simulate Page Replacement
8
Algorithms FIFO
Simulate Page Replacement
9
Algorithms LRU
Simulate Page Replacement
10
Algorithms OPTIMAL
11 C program that demonstrates use of
FORK
12 C program that demonstrates use of
WAIT
13 C program that demonstrates use of
PAUSE
14 C program that demonstrates use of
EXECVP
15 C program that demonstrates use of
KILL
16 C program that demonstrates use of
WAITPID
17 C program that demonstrates use of
SIGNAL
18 C program that demonstrates use of
RAISE
19 C program that demonstrates use of
EXIT
20 C program that demonstrates
PAGING
21 C program that demonstrates
SWAPPING
22 C program that demonstrates
SEGMENTATION
23 C program that demonstrates
CONTIGUOUS MEMORY
ALLOCATION
24 C program that demonstrates PIPE
25 C program that demonstrates WAIT
TIMEOUT
PROGRAM:11
C Program that demonstrates use of FORK

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

int main() {
pid_t child_pid;

// Create a new process (child) by calling fork()

child_pid = fork();

// Check if fork() failed

if (child_pid == -1) {
perror("fork");
return 1;
}

// Code that runs in both the parent and child processes

if (child_pid == 0) {

// This code runs in the child process

printf("Child Process: PID = %d\n", getpid());


} else {

// This code runs in the parent process

printf("Parent Process: PID = %d, Child PID = %d\n", getpid(),


child_pid);
}

return 0;
}
PROGRAM: (PROCESS SYSTEM CALLS)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char *argv[])


{
int pid = fork();

if (pid < 0)
{
printf("fork failed\n");
exit(1);
}
else if (pid == 0)
{
// In child process
execlp("ls", "ls", NULL); // Correct usage of execlp
printf("execlp failed\n"); // This will only print if execlp fails
exit(1);
}
else
{
// In parent process
printf("Process id is - %d\n", getpid());
wait(NULL); // Wait for the child process to finish
exit(0);
}
}
PROGRAM :( FIRST COME FIRST SERVE SCHEDULING)
#include<stdio.h>
struct process
{
int pid;
int bt;
int wt,tt;
}
p[10];
int main()
{
int i,n,totwt,tottt,avg1,avg2;
clrscr();
printf("enter the no of process \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf("enter the burst time n");
scanf("%d",&p[i].bt);
}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i ++;
}
i=1;
totwt=tottt=0;
printf("\n processid \t bt\t wt\t tt\n");
while(i<=n)
{
printf("\n\t%d \t%d \t%d \t%d",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
}
avg1=totwt/n;
avg2=tottt/n;
printf("\navg1=%d \t avg2=%d \t",avg1,avg2);
getch();
return 0;
}
PROGRAM: (SHORTEST JOB FIRST SCHEDULING)
#include<stdio.h>
#include<conio.h>
struct process
{
int pid;
int bt;
int wt;
int tt;
}
p[10],temp;
int main()
{
int
i,j,n,totwt,tottt;
float avg1,avg2;
clrscr();
printf("\nEnter the number of process:\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf("\nEnter the burst time:\t");
scanf("%d",&p[i].bt);
}
for(i=1;i<n;i++){
for(j=i+1;j<=n;j++)
{
if(p[i].bt>p[j].bt)
{
temp.pid=p[i].pid;
p[i].pid=p[j].pid;
p[j].pid=temp.pid;
temp.bt=p[i].bt;p[i].bt=p[j].bt;
p[j].bt=temp.bt;
}
}
}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n){
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;
}
i=1;
totwt=tottt=0;
printf("\nProcess id \tbt \twt \ttt");
while(i<=n){
printf("\n\t%d \t%d \t%d t%d\n",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
}
avg1=totwt/n;
avg2=tottt/n;
printf("\nAVG1=%f\t AVG2=%f",avg1,avg2);
getch();
return 0;}

You might also like