0% found this document useful (0 votes)
53 views43 pages

Btech 2-2 O.S Lab MANUAL-1

The document is a lab manual for B.Tech 2-2 students focusing on operating systems, specifically UNIX commands and programming. It includes basic UNIX commands, examples of system calls like fork and exec, and simulations of various UNIX commands and CPU scheduling algorithms such as FCFS, SJF, Priority, and Round Robin. The manual provides code snippets and expected outputs for practical understanding.

Uploaded by

Hemanth Atla
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)
53 views43 pages

Btech 2-2 O.S Lab MANUAL-1

The document is a lab manual for B.Tech 2-2 students focusing on operating systems, specifically UNIX commands and programming. It includes basic UNIX commands, examples of system calls like fork and exec, and simulations of various UNIX commands and CPU scheduling algorithms such as FCFS, SJF, Priority, and Round Robin. The manual provides code snippets and expected outputs for practical understanding.

Uploaded by

Hemanth Atla
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/ 43

B.

Tech 2-2 operating system lab manual

1.Practicing of basic UNIX Commands?


Unix operating system is multitasking, which also gives an opportunity for two or more
users to use its benefits
Basic Commands in Unix
cd: it changes the directory
Syntax: cd [OPTION] directory
mv: This command is used to rename files or move files.
Syntax:mv [OPTION]source destination

cal: This command is used to show the calendar.


Syntax:csal [month] year]

date: It is used to show the system time and date.


Syntax:date [+format]

banner: It is used to show a large banner on a standard output.


Syntax:banner message

who: This command is used to show the user's list logged in currently.
Syntax:who [option] ... [file][arg1]

touch: It creates a new file or upgrades its timestamp.


Syntax:touch [OPTION]...[FILE]

cat: This command is used to concatenate files and display them on stdout.
Syntax:cat [OPTION]…[FILE]

copy: This command is used to copy files.


Syntax:cp [OPTION]source destination

rm: This command is used to remove directories and files.


Syntax:rm [OPTION]...[FILE]

mkdir: It creates a directory.


Syntax: mkdir [OPTION] directory

rmkdir: It removes a directory.


Syntax: rmdir[OPTION] directory
pwd: It prints the current working directory.
Syntax:pwd [OPTION]

2.Write programs using the following UNIX operating system calls fork, exec, getpd,
exit, wait, close, stat, opendir and readdir?
i) fork() and exec():
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid == 0) { // Child process
execlp("ls", "ls", "-l", NULL); // Execute `ls -l`
} else if (pid > 0) { // Parent process
wait(NULL); // Wait for the child process to finish
} else {
perror("Fork failed");
}
return 0;
}
1. Exit():
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Program is exiting.\n");
exit(0); // Exit with status code 0
}
2. wait() :
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
pid_t pid = fork();
if (pid == 0) { // Child process
printf("Child process\n");
_exit(0);
} else { // Parent process
wait(NULL); // Wait for child process to finish
printf("Child process finished\n");
}
return 0;
}
3. close():
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int fd = open("example.txt", O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (fd != -1) {
write(fd, "Hello, World!\n", 14);
close(fd); // Close the file descriptor
} else {
perror("Failed to open file");
}
return 0;
}
4. stat():
#include <stdio.h>
#include <sys/stat.h>
int main() {
struct stat fileStat;
if (stat("example.txt", &fileStat) == 0) {
printf("File size: %ld bytes\n", fileStat.st_size);
printf("Last modified: %ld\n", fileStat.st_mtime);
} else {
perror("stat failed");
}
return 0;
}
5. opendir() and readdir():
#include <stdio.h>
#include <dirent.h>

int main() {
DIR *dir = opendir(".");
if (dir) {
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
} else {
perror("Failed to open directory");
}
return 0;
}

3. Simulate UNIX Commands like cp,ls,grep,etc.,


ANS: SIMULATE cp COMMAND USING C:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
main(int argc, char **argv)
{
char buffer[1024];
int files[2];
ssize_t count;
/* Check for insufficient parameters */
if (argc < 3)
return -1;
files[0] = open(argv[1], O_RDONLY);
if (files[0] == -1)
return -1;
files[1] = open(argv[2], O_WRONLY | O_CREAT | S_IRUSR | S_IWUSR);
if (files[1] == -1)
{
close(files[0]);
return -1;
}
while ((count = read(files[0], buffer, sizeof(buffer))) != 0)
write(files[1], buffer, count);
}

OUTPUT:
pugazh@Pugazh-PC:/mnt/e/ospgm$ ./a.out cp.c cp1.c

Simulate ls Command using C


#include<stdio.h>
#include<dirent.h>
main()
{
Char dirname[10];
DIR*p;
struct dirent*d;
printf(“Enter directory name:\n”);
scanf(“%s”,dirname);
p=opendir(dirname);
if(p==NULL)
{
perror(“Cannot find directory”);
exit(-1);
}
while(d=readdir(p))
printf(“%s”,d->d_name);
}

OUTPUT:
pugazh@Pugazh-PC:/mnt/e/ospgm$ gcc ls.c
pugazh@Pugazh-PC:/mnt/e/ospgm$ ./a.out
Enter directory name
Hello
Cannot find directory: No such file or directory
pugazh@Pugazh-PC:/mnt/e/ospgm$ ./a.out
Enter directory name
Sam
HillCipher.javaMD5.javaObjectSigningExample.javaplayfair.javaRailFence2.java
RSA.javaSHA1.javaVigenereCipher.java
pugazh@Pugazh-PC:/mnt/e/ospgm$

Simulate grep command using C:


#include<stdio.h>
#include<string.h>
void main()
{
char fn[10],pat[10],temp[200];
FILE *fp;
printf("Enter file name\n");
scanf("%s",fn);
printf("Enter pattern to be searched\n”);
scanf("%s",pat);
fp=fopen(fn,"r");
while(!feof(fp))
{
fgets(temp,1000,fp);
if(strstr(temp,pat))
printf("%s",temp);
}
fclose(fp);
}

OUTPUT:
pugazh@Pugazh-PC:/mnt/e/ospgm$ gcc grep.c
pugazh@Pugazh-PC:/mnt/eospgm$ ./a.out
Enter file name
grep.c
Enter pattern to be searched
printf(“Enter file name\n”);
printf(“Enter pattern to be searched\n”);
printf(“%s”,temp);
pugazh@Pugazh-PC:/mnt/e/ospgm$

4. Simulate the following CPU Scheduling algorithms


A) FCFS Scheduling
#include<stdio.h>
void main()
{
int i,n,sum,wt,tat,twt,ttat;
int t[10];
float awt,atat;
printf ("Enter number of processors:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the Burst Time of the process %d",i+1);
scanf("\n %d",&t[i]);
}
printf("\n\n FIRST COME FIRST SERVE SCHEDULING ALGORITHM \n");
printf("\n Process ID \t Waiting Time \t Turn Around Time \n");
printf("1 \t\t 0 \t\t %d \n",t[0]);
sum=0; twt=0; ttat=t[0];
for(i=1;i<n;i++)
{
sum+=t[i-1]; wt=sum; tat=sum+t[i]; twt=twt+wt; ttat=ttat+tat;
printf("\n %d \t\t %d \t\t %d",i+1,wt,tat); printf("\n\n");
}
awt=(float)twt/n; atat=(float)ttat/n;
printf("\n Average Waiting Time %4.2f",awt);
printf("\n Average Turnaround Time %4.2f",atat);
}
OUTPUT:
Enter number of processors:
3
Enter the Burst Time of the process 12
Enter the Burst Time of the process 25
Enter the Burst Time of the process 34
FIRST COME FIRST SERVE SCHEDULING ALGORITHM
Process_ID Waiting time Turn Around Time
1 0 2
2 2 7
3 7 11

Average Waiting Time 3.00


Average Turnaround Time 6.67
Process exited after 30.95 seconds with return value 30
Press any key to continue …

B)SJF Scheduling
Code:
#include<stdio.h>
int main()
{
int i,j,k,n,sum,wt[10],tt[10],twt,ttat; int t[10],p[10];
float awt,atat;
printf("Enter number of process\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the Burst Time of Process %d",i); scanf("\n %d",&t[i]);
}
for(i=0;i<n;i++) p[i]=i; for(i=0;i<n;i++)
{
for(k=i+1;k<n;k++)
{
if(t[i]>t[k])
{
int temp; temp=t[i]; t[i]=t[k]; t[k]=temp; temp=p[i]; p[i]=p[k]; p[k]=temp;
}
}
printf("\n\n SHORTEST JOB FIRST SCHEDULING ALGORITHM");
printf("\n PROCESS ID \t BURST TIME \t WAITING TIME \t TURNAROUNDTIME \n\n");
wt[0]=0;
for(i=0;i<n;i++)
{
sum=0; for(k=0;k<i;k++)
{
wt[i]=sum+t[k]; sum=wt[i];
}
}
for(i=0;i<n;i++)
{
tt[i]=t[i]+wt[i];
}
for(i=0;i<n;i++)
{
printf("%5d \t\t5%d \t\t %5d \t\t %5d \n\n",p[i],t[i],wt[i],tt[i]);
}
twt=0; ttat=t[0]; for(i=1;i<n;i++)
{
twt=twt+wt[i];
ttat=ttat+tt[i];
}
awt=(float)twt/n; atat=(float)ttat/n;
printf("\n AVERAGE WAITING TIME %4.2f",awt); printf("\n AVERAGE TURN AROUND TIME
%4.2f",atat);
}
}
OUTPUT:
Enter number of process 3
Enter the Burst Time of Process 04
Enter the Burst Time of Process 13
Enter the Burst Time of Process 25
SHORTEST JOB FIRST SCHEDULING ALGORITHM
PROCESS ID BURST TIME WATING TIME TURNAROUND TIME
1 3 0
0 4 3
2 5 7
AVERAGE WAITING TIME 3.33
AVERAGE TURN AROUND TIME 7.33
Process exited after 16.62 seconds with return value 0
Press any key to continue …

C)Priority Scheduling.
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,n,tat[10],wt[10],bt[10],pid[10],pr[10],t,twt=0,ttat=0; float awt,atat;
printf("\n-----------PRIORITY SCHEDULING \n");
printf("Enter the No of Process: ");
scanf("%d", &n);
for (i=0;i<n;i++)
{
pid[i] = i;
printf("Enter the Burst time of Pid %d : ",i);
scanf("%d",&bt[i]);
printf("Enter the Priority of Pid %d : ",i);
scanf ("%d",&pr[i]);
}
// Sorting start for (i=0;i<n;i++) for(j=i+1;j<n;j++)
{
if (pr[i] > pr[j] )
{
t = pr[i]; pr[i] = pr[j]; pr[j] = t;
t = bt[i]; bt[i] = bt[j]; bt[j] = t;
}
}
// Sorting finished tat[0] = bt[0]; wt[0] = 0;
for (i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = wt[i] + bt[i];
}
printf("\n \n");
printf("Pid\t Priority\tBurst time\t WaitingTime\tTurnArroundTime\n"); printf("\n \
n");
for(i=0;i<n;i++)
{
printf("\n%d\t\t%d\t%d\t\t%d\t\t%d",pid[i],pr[i],bt[i],wt[i],tat[i]);
}
for(i=0;i<n;i++)
{
ttat = ttat+tat[i]; twt = twt + wt[i];
}
awt = (float)twt / n; atat = (float)ttat / n;
printf("\n\nAvg.Waiting Time: %f\nAvg.Turn Around Time: %f\n",awt,atat);
}

OUTPUT:
___PRIORITY SCHEDULING ____
Enter the No of Process: 4
Enter the Burst time of Pid 0 : 2
Enter the Priority of Pid 0 : 3
Enter the Burst time of Pid 1 : 6
Enter the Priority of Pid 1 : 2
Enter the Burst time of Pid 2 : 4
Enter the Priority of Pid 2 : 1
Enter the Burst time of Pid 3 : 5
Enter the Priority of Pid 3 : 7

Pid Priority Burst time WaitingTime TurnArroundTime


…………………………….
0 1 4 0 4
12 1 4 10
2 3 2 10 12
3 7 5 12 17

Avg.Waiting Time: 6.500000


Avg.Turn Around Time: 10.750000

Process exited after 56.53 seconds with return value 61


Press any key to continue . . .
D)Round Robin Scheduling:-
#include<stdio.h>
#include<conio.h>
void main()
{
int ts,pid[10],need[10],wt[10],tat[10],i,j,n,n1; int bt[10],flag[10],ttat=0,twt=0;
float awt,atat;
printf("\t\t ROUND ROBIN SCHEDULING \n");
printf("Enter the number of Processors \n");
scanf("%d",&n);
n1=n;
printf("\n Enter the Timeslice \n");
scanf("%d",&ts); for(i=1;i<=n;i++)
{
printf("\n Enter the process ID %d",i);
scanf("%d",&pid[i]);
printf("\n Enter the Burst Time for the process");
scanf("%d",&bt[i]);
need[i]=bt[i];
}
for(i=1;i<=n;i++)
{
flag[i]=1; wt[i]=0;
}
while(n!=0)
{
for(i=1;i<=n;i++)
{
if(need[i]>=ts)
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0)) wt[j]+=ts;
}
need[i]-=ts; if(need[i]==0)
{
flag[i]=0; n--;
}
}
else
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0)) wt[j]+=need[i];
}
need[i]=0; n--; flag[i]=0;
}
}
}
for(i=1;i<=n1;i++) for(i=1;i<=n1;i++)
{
tat[i]=wt[i]+bt[i]; twt=twt+wt[i]; ttat=ttat+tat[i];
}
awt=(float)twt/n1; atat=(float)ttat/n1;
printf("\n\n ROUND ROBIN SCHEDULING ALGORITHM \n\n");
printf("\n\n Process \t Process ID \t BurstTime \t Waiting Time \t TurnaroundTime \n ");
for(i=1;i<=n1;i++)
{
printf("\n %5d \t %5d \t\t %5d \t\t %5d \t\t %5d \n", i,pid[i],bt[i],wt[i],tat[i]);
}
printf("\n The average Waiting Time=%4.2f",awt);
printf("\n The average Turn around Time=%4.2f",atat);
}
OUTPUT:
ROUND ROBIN SCHEDULING
Enter the number of Processors 4

Enter the Timeslice 5

Enter the process ID 1 5

Enter the Burst Time for the process1 0 Enter the process ID 2 6
Enter the Burst Time for the process1 5 Enter the process ID 3 7
Enter the Burst Time for the process2 0 Enter the process ID 4 8
Enter the Burst Time for the process2 5

ROUND ROBIN SCHEDULING ALGORITHM

Process Process ID Burst Time Waiting Time Turnaround Time

1 5 10 15

2 6 15 25

3 7 20 25

4 8 25 20

The Average Waiting Time = 21.2

The Average Turn Around Time = 38.75

5) Control the number of ports opened by the Operating System with


a)Semaphore b)Monitors

a) Semaphore:
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#define MAX_PORTS 3 // Maximum number of ports that can be opened concurrently
sem_t port_semaphore; // Semaphore to control port access
void *use_port(void *arg)
{
int thread_id = *(int *)arg;
printf("Thread %d: Waiting to open a port...\n", thread_id);
sem_wait(&port_semaphore); // Decrement semaphore
printf("Thread %d: Port opened. Using port...\n", thread_id);
printf("Thread %d: Done. Closing port...\n", thread_id);
sem_post(&port_semaphore); // Increment semaphore
return NULL;
}

int main()
{
pthread_t threads[5];
int thread_ids[5]; sem_init(&port_semaphore, 0, MAX_PORTS);

for (int i = 0; i < 5; i++) {


thread_ids[i] = i + 1;
pthread_create(&threads[i], NULL, use_port, &thread_ids[i]);
}
for (int i = 0; i < 5; i++)
{
pthread_join(threads[i], NULL);
}
sem_destroy(&port_semaphore);
return 0;
}

OUTPUT:
Thread 1: Waiting to open a port...
Thread 2: Waiting to open a port...
Thread 1: Port opened. Using port...
Thread 2: Port opened. Using port...
Thread 3: Waiting to open a port...
Thread 1: Done. Closing port...
Thread 3: Port opened. Using port...
...

b)Monitor:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
typedef struct
{
int availablePorts;
pthread_mutex_t lock;
pthread_cond_t condition;
}
PortMonitor;
void initializeMonitor(PortMonitor *monitor, int maxPorts)
{
monitor->availablePorts = maxPorts;
pthread_mutex_init(&monitor->lock, NULL);
pthread_cond_init(&monitor->condition, NULL);
}

void openPort(PortMonitor *monitor, int threadId)


{
pthread_mutex_lock(&monitor->lock);
while (monitor->availablePorts == 0)
{
printf("Thread %d is waiting for a port...\n", threadId);
pthread_cond_wait(&monitor->condition, &monitor->lock);
}
monitor->availablePorts--;
printf("Thread %d has opened a port. Available ports: %d\n", threadId, monitor-
>availablePorts);
pthread_mutex_unlock(&monitor->lock);
}
void closePort(PortMonitor *monitor, int threaded)
{
pthread_mutex_lock(&monitor->lock);
monitor->availablePorts++;
printf("Thread %d has closed a port. Available ports: %d\n", threadId, monitor-
>availablePorts);
pthread_cond_broadcast(&monitor->condition);
pthread_mutex_unlock(&monitor->lock);
}
void *portUser(void *arg) {
int threadId = *(int *)arg;
extern PortMonitor monitor;
openPort(&monitor, threadId);
sleep(2); // Simulate using the port
closePort(&monitor, threadId);
return NULL;
}
// Global monitor object
PortMonitor monitor;
int main()
{
const int maxPorts = 3; // Maximum number of ports
const int totalThreads = 5; // Number of threads (users)
pthread_t threads[totalThreads];
int threadIds[totalThreads];
initializeMonitor(&monitor, maxPorts);
// Create threads to simulate port usage
for (int i = 0; i < totalThreads; i++)
{
threadIds[i] = i + 1;
pthread_create(&threads[i], NULL, portUser, &threadIds[i]);
}

// Wait for all threads to finish


for (int i = 0; i < totalThreads; i++) {
pthread_join(threads[i], NULL);
}

// Destroy the monitor


pthread_mutex_destroy(&monitor.lock);
pthread_cond_destroy(&monitor.condition);

return 0;
}
OUTPUT:
Thread 1 has opened a port. Available ports: 2
Thread 2 has opened a port. Available ports: 1
Thread 3 has opened a port. Available ports: 0
Thread 4 is waiting for a port...
Thread 5 is waiting for a port...
Thread 1 has closed a port. Available ports: 1
Thread 4 has opened a port. Available ports: 0
Thread 2 has closed a port. Available ports: 1
Thread 5 has opened a port. Available ports: 0
...
6) Write a program to illustrate concurrent execution of threads using the pthreads library?

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
// Thread function
void *printMessage(void *arg)
{
int threadId = *(int *)arg;
printf("Thread %d: Starting execution\n", threadId);
printf("Thread %d: Finishing execution\n", threadId);
return NULL;
}
int main()
{
const int numThreads = 5; // Number of threads to create
pthread_t threads[numThreads];
int threadIds[numThreads];
for (int i = 0; i < numThreads; i++)
{
threadIds[i] = i + 1;
if (pthread_create(&threads[i], NULL, printMessage, &threadIds[i]) != 0)
{
perror("Failed to create thread");
}
printf("Main: Thread %d has been created\n", threadIds[i]);
}
// Wait for all threads to complete
for (int i = 0; i < numThreads; i++)
{
pthread_join(threads[i], NULL);
printf("Main: Thread %d has completed\n", threadIds[i]);
}
printf("Main: All threads have finished execution\n");
return 0;
}
OUTPUT:
Main: Thread 1 has been created
Main: Thread 2 has been created
Main: Thread 3 has been created
Main: Thread 4 has been created
Main: Thread 5 has been created
Thread 1: Starting execution
Thread 2: Starting execution
Thread 3: Starting execution
Thread 4: Starting execution
Thread 5: Starting execution
Thread 1: Finishing execution
Main: Thread 1 has completed
Thread 2: Finishing execution
Main: Thread 2 has completed
Thread 3: Finishing execution
Main: Thread 3 has completed
Thread 4: Finishing execution
Main: Thread 4 has completed
Thread 5: Finishing execution
Main: Thread 5 has completed
Main: All threads have finished execution
7) Write a program to solve producer-consumer problem using Semaphores?

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#define BUFFER_SIZE 5 // Size of the shared buffer

int buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
sem_t empty;
sem_t full;
pthread_mutex_t mutex;
void *producer(void *arg)
{
for (int i = 1; i <= 10; i++)
{
sem_wait(&empty);
pthread_mutex_lock(&mutex);
buffer[in] = i;
printf("Producer produced: %d\n", i);
in = (in + 1) % BUFFER_SIZE;
pthread_mutex_unlock(&mutex);
sem_post(&full);
sleep(1);
}
return NULL;
}
void *consumer(void *arg)
{
for (int i = 1; i <= 10; i++)
{
sem_wait(&full);
pthread_mutex_lock(&mutex);

int item = buffer[out];


printf("Consumer consumed: %d\n", item);
out = (out + 1) % BUFFER_SIZE;
pthread_mutex_unlock(&mutex);
sem_post(&empty);
sleep(2);
}
return NULL;
}

int main()
{
pthread_t prodThread, consThread;
sem_init(&empty, 0, BUFFER_SIZE);
sem_init(&full, 0, 0);
pthread_mutex_init(&mutex, NULL);
pthread_create(&prodThread, NULL, producer, NULL);
pthread_create(&consThread, NULL, consumer, NULL);
pthread_join(prodThread, NULL);
pthread_join(consThread, NULL);
sem_destroy(&empty);
sem_destroy(&full);
pthread_mutex_destroy(&mutex);
return 0;
}
OUTPUT:
Producer produced: 1
Consumer consumed: 1
Producer produced: 2
Producer produced: 3
Consumer consumed: 2
Producer produced: 4
Consumer consumed: 3
Producer produced: 5
Consumer consumed: 4
Producer produced: 6

8) Implement the following memory allocation methods for fixed partition.


a) First fit b)Worst fit c)Best fit
1. First Fit:

 First Fit allocates the first partition that is large enough to hold the process.
2. Worst Fit:
 Worst Fit allocates the largest available partition to the process, leaving the most
unused space in the partition.
3. Best Fit:
 Best Fit allocates the smallest available partition that is large enough to
accommodate the process, leaving the least unused space.
CODE:
#include <stdio.h>
#include <stdlib.h>
// Structure to represent a Partition
typedef struct {
int size;
int isOccupied;
int processID;
}
Partition;
typedef struct
{
int processID;
int size;
}
Process;
void firstFit(Partition partitions[], int numPartitions, Process processes[], int
numProcesses);
void worstFit(Partition partitions[], int numPartitions, Process processes[], int
numProcesses);
void bestFit(Partition partitions[], int numPartitions, Process processes[], int
numProcesses);
void printPartitions(Partition partitions[], int numPartitions);

int main()
{
Partition partitions[] =
{
{100, 0, -1}, {200, 0, -1}, {300, 0, -1}, {150, 0, -1}, {250, 0, -1},
{120, 0, -1}, {170, 0, -1}, {220, 0, -1}, {50, 0, -1}, {180, 0, -1}
};
Process processes[] = {
{1, 120}, {2, 90}, {3, 180}, {4, 150}, {5, 60},
{6, 110}, {7, 200}, {8, 130}
};
int numPartitions = sizeof(partitions) / sizeof(partitions[0]);
int numProcesses = sizeof(processes) / sizeof(processes[0]);
printf("First-Fit Allocation:\n");
firstFit(partitions, numPartitions, processes, numProcesses);
printPartitions(partitions, numPartitions);
for (int i = 0; i < numPartitions; i++) {
partitions[i].isOccupied = 0;
partitions[i].processID = -1;
}
printf("\nWorst-Fit Allocation:\n");
worstFit(partitions, numPartitions, processes, numProcesses);
printPartitions(partitions, numPartitions);
for (int i = 0; i < numPartitions; i++)
{
partitions[i].isOccupied = 0;
partitions[i].processID = -1;
}
printf("\nBest-Fit Allocation:\n");
bestFit(partitions, numPartitions, processes, numProcesses);
printPartitions(partitions, numPartitions);
return 0;
}
// First Fit allocation
void firstFit(Partition partitions[], int numPartitions, Process processes[], int
numProcesses)
{
for (int i = 0; i < numProcesses; i++)
{
for (int j = 0; j < numPartitions; j++)
{
if (partitions[j].isOccupied == 0 && partitions[j].size >= processes[i].size)
{
partitions[j].isOccupied = 1;
partitions[j].processID = processes[i].processID;
printf("Process %d allocated to Partition %d\n", processes[i].processID, j);
break;
}
}
}
}

// Worst Fit allocation


void worstFit(Partition partitions[], int numPartitions, Process processes[], int
numProcesses)
{
for (int i = 0; i < numProcesses; i++)
{
int worstIndex = -1;
int maxDifference = -1;
for (int j = 0; j < numPartitions; j++)
{
if (partitions[j].isOccupied == 0 && partitions[j].size >= processes[i].size)
{
int difference = partitions[j].size - processes[i].size;
if (difference > maxDifference)
{
maxDifference = difference;
worstIndex = j;
}
}
}

if (worstIndex != -1)
{
partitions[worstIndex].isOccupied = 1;
partitions[worstIndex].processID = processes[i].processID;
printf("Process %d allocated to Partition %d\n", processes[i].processID,
worstIndex);
}
}
}

// Best Fit allocation


void bestFit(Partition partitions[], int numPartitions, Process processes[], int
numProcesses)
{
for (int i = 0; i < numProcesses; i++)
{
int bestIndex = -1;
int minDifference = 999999; // Arbitrarily large value

for (int j = 0; j < numPartitions; j++)


{
if (partitions[j].isOccupied == 0 && partitions[j].size >= processes[i].size)
{
int difference = partitions[j].size - processes[i].size;
if (difference < minDifference) {
minDifference = difference;
bestIndex = j;
}
}
}

if (bestIndex != -1) {
partitions[bestIndex].isOccupied = 1;
partitions[bestIndex].processID = processes[i].processID;
printf("Process %d allocated to Partition %d\n", processes[i].processID,
bestIndex);
}
}
}

// Function to print the current status of all partitions


void printPartitions(Partition partitions[], int numPartitions) {
for (int i = 0; i < numPartitions; i++)
{
if (partitions[i].isOccupied == 0)
{
printf("Partition %d: Free, Size %d\n", i, partitions[i].size);
}
Else
{
printf("Partition %d: Occupied by Process %d, Size %d\n", i,
partitions[i].processID, partitions[i].size);
}
}
}
OUTPUT:
First-Fit Allocation:
Process 1 allocated to Partition 0
Process 2 allocated to Partition 1
Process 3 allocated to Partition 2
Process 4 allocated to Partition 3
Process 5 allocated to Partition 8
Process 6 allocated to Partition 5
Process 7 allocated to Partition 6
Process 8 allocated to Partition 7
Partition 0: Occupied by Process 1, Size 100
Partition 1: Occupied by Process 2, Size 200
Partition 2: Occupied by Process 3, Size 300
Partition 3: Occupied by Process 4, Size 150
Partition 4: Free, Size 250
Partition 5: Occupied by Process 6, Size 120
Partition 6: Occupied by Process 7, Size 170
Partition 7: Occupied by Process 8, Size 220
Partition 8: Free, Size 50
Partition 9: Free, Size 180

Worst-Fit Allocation:
Process 1 allocated to Partition 2
Process 2 allocated to Partition 1
Process 3 allocated to Partition 9
Process 4 allocated to Partition 6
Process 5 allocated to Partition 4
Process 6 allocated to Partition 3
Process 7 allocated to Partition 7
Process 8 allocated to Partition 0
Partition 0: Occupied by Process 8, Size 100
Partition 1: Occupied by Process 2, Size 200
Partition 2: Occupied by Process 1, Size 300
Partition 3: Occupied by Process 6, Size 120
Partition 4: Occupied by Process 5, Size 250
Partition 5: Free, Size 120
Partition 6: Occupied by Process 4, Size 150
Partition 7: Occupied by Process 7, Size 170
Partition 8: Free, Size 50
Partition 9: Occupied by Process 3, Size 180

Best-Fit Allocation:
Process 1 allocated to Partition 5
Process 2 allocated to Partition 0
Process 3 allocated to Partition 9
Process 4 allocated to Partition 6
Process 5 allocated to
9)Simulate the following page replacement algorithms
a) FIFO b) LRU c) LFU
FIFO Page replacement algorithm.

include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
void main()
{
printf("\n \t\t\t FIFI PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of frames . . ");
scanf("%d",&nof);
printf("Enter number of reference string..\n"); scanf("%d",&nor);
printf("\n Enter the reference string.."); for(i=0;i<nor;i++) scanf("%d",&ref[i]);
printf("\nThe given reference string:"); for(i=0;i<nor;i++) printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf("\n"); for(i=0;i<nor;i++)
{
flag=0;
printf("\n\t Reference np%d->\t",ref[i]); for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1; break;
}
}
if(flag==0)
{
pf++; victim++;
victim=victim%nof; frm[victim]=ref[i]; for(j=0;j<nof;j++) printf("%4d",frm[j]);
}
}
printf("\n\n\t\t No.of pages faults. .%d",pf);
}

OUTPUT:
Enter no.of frames . . 4
Enter number of reference string . 6

Enter the reference string..5 6


4
1
2
3
The given reference string: 5 6 4 1 2 3
Reference np5 -> 5 -1 -1 -1
Reference np6 -> 5 6 -1 -1
Reference np4 -> 5 6 4 -1
Reference np1 -> 5 6 4 1
Reference np2 -> 2 6 4 1
Reference np3 -> 2 3 4 1
No.of pages faults…6
Process exited after 102.9 seconds with return value 27
Press any key to continue. . .

b) LRU Page replacement algorithm.


#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],lrucal[50],count=0;
int lruvictim();
void main()
{
printf("\n\t\t\t LRU PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of Frames. . ");
scanf("%d",&nof);
printf(" Enter no.of reference string..");
scanf("%d",&nor);
printf("\n Enter reference string..");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("\n\n\t\t LRU PAGE REPLACEMENT ALGORITHM ");
printf("\n\t The given reference string:");
printf("\n ");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
{
frm[i]=-1; lrucal[i]=0;
}
for(i=0;i<10;i++) recent[i]=0; printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\t Reference NO %d->\t",ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1; break;
}
}
if(flag==0)
{
count++; if(count<=nof) victim++;
else victim=lruvictim(); pf++; frm[victim]=ref[i]; for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
recent[ref[i]]=i;
}
printf("\n\n\t No.of page faults ..%d",pf);
}
int lruvictim()
{
int i,j,temp1,temp2; for(i=0;i<nof;i++)
{
temp1=frm[i]; lrucal[i]=recent[temp1];
}
temp2=lrucal[0]; for(j=1;j<nof;j++)
{
if(temp2>lrucal[j]) temp2=lrucal[j];
}
for(i=0;i<nof;i++)
if(ref[temp2]==frm[i]) return i;
return 0;
}
OUTPUT:-

LRU PAGE REPLACEMENT ALGORITHM


Enter no.of Frames. . 3
Enter no.of reference string .6
Enter reference string..6
5
2
3
1
LRU PAGE REPLACEMENT ALGORITHM
The given reference string:
---------------------------- 6 5 4 2 3 1
Reference NO 6 -> 6 -1 -1
Reference NO 5 -> 6 5 -1
Reference No 4 -> 2 5 4
Reference NO 2 -> 2 3 4
Reference No 1 -> 2 3 1
No.of page faults …6

Process exited after 59.27 seconds with return value 25


Press any key to continue…
c) Page replacement algorithm.

#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],optcal[50],count=0;
int optvictim();
void main()
{
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHN");
printf("\n ");
printf("\nEnter the no.of frames");
scanf("%d",&nof);
printf("Enter the no.of reference string");
scanf("%d",&nor);
printf("Enter the reference string"); for(i=0;i<nor;i++) scanf("%d",&ref[i]);
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHM");
printf("\n ");
printf("\nThe given string");
printf("\n \n");
for(i=0;i<nor;i++)\
printf("%4d",ref[i]);
for(i=0;i<nof;i++)
{
frm[i]=-1;
optcal[i]=0;
}
for(i=0;i<10;i++) recent[i]=0; printf("\n"); for(i=0;i<nor;i++)
{
flag=0;
printf("\n\tref no % ->\t",ref[i]); for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1; break;
}
}
if(flag==0) { count++; if(count<=nof) victim++;
else victim=optvictim(i); pf++; frm[victim]=ref[i];
for(j=0;j<nof;j++) printf("%4d",frm[j]);
}
}
printf("\n Number of page faults: %d",pf); getch();
}
int optvictim(int index)
{
int i,j,temp,notfound; for(i=0;i<nof;i++)
{
notfound=1;
for(j=index;j<nor;j++)
if(frm[i]==ref[j])
{
notfound=0;
optcal[i]=j;
break;
}
if(notfound==1) return i;
}
temp=optcal[0];
for(i=1;i<nof;i++)
if(temp<optcal[i])
temp=optcal[i];
for(i=0;i<nof;i++)
if(frm[temp]==frm[i])
return i;
return 0;
}

OUTPUT:

OPTIMAL PAGE REPLACEMENT ALGORITHN


.. . .. . .. . .. . .. . .. . .
Enter the no.of frames 3
Enter the no.of reference string 6
Enter the reference string 6
5
4
2
3
1
OPTIMAL PAGE REPLACEMENT ALGORITHM
……………………………….
The given string
……………………..
6 5 4 2 3 1
Ref no -> 6 -1 -1
Ref no -> 6 5 -1
Ref no -> 6 5 4
Ref no -> 2 5 4
Ref no -> 3 5 4
Ref no -> 1 5 4
Number of page faults: 6
10) Simulate the Paging Technique of memory management
Ans: #Simulating the paging technique of memory management involves demonstrating
how logical memory addresses are translated into physical memory addresses using
page tables. Here's a simplified simulation in C:
Key Concepts:
1. Paging:
o Divides memory into fixed-size blocks called pages.
o Corresponding blocks in physical memory are called frames.
o Logical addresses are divided into two parts:
 Page Number (PN): Identifies which page the address belongs to.
 Page Offset (PO): Identifies the exact location within the page.
o A page table maps logical pages to physical frames.
2. Translation:
o Logical Address = (Page Number, Page Offset)
o Physical Address = (Frame Number, Page Offset)
CODE:
#include <stdio.h>
#include <stdlib.h>
// Define page size and memory size
#define PAGE_SIZE 4 // Size of each page in KB
#define MEMORY_SIZE 16 // Total physical memory size in KB
void simulatePaging(int logicalAddresses[], int numAddresses, int pageTable[], int
numPages);
int main() {
int numPages = MEMORY_SIZE / PAGE_SIZE;
// Page table mapping logical pages to physical frames
int pageTable[] = {3, 1, 4, 2}; // Logical page i is mapped to frame pageTable[i]
// Logical addresses to translate
int logicalAddresses[] = {5, 8, 14, 18, 2, 9}; // Logical addresses in KB
int numAddresses = sizeof(logicalAddresses) / sizeof(logicalAddresses[0]);
printf("Simulating Paging Technique:\n");
simulatePaging(logicalAddresses, numAddresses, pageTable, numPages);
return 0;
}
// Function to simulate paging
void simulatePaging(int logicalAddresses[], int numAddresses, int pageTable[], int
numPages) {
printf("Logical Address -> Physical Address\n");
for (int i = 0; i < numAddresses; i++)
{
int logicalAddress = logicalAddresses[i];
int pageNumber = logicalAddress / PAGE_SIZE;
int pageOffset = logicalAddress % PAGE_SIZE;
if (pageNumber >= numPages)
{
printf("Logical Address %d: Invalid (Page number %d out of range)\n",
logicalAddress, pageNumber);
}
else
{
int frameNumber = pageTable[pageNumber];
number
int physicalAddress = frameNumber * PAGE_SIZE + pageOffset;
printf("Logical Address %d: Page %d, Offset %d -> Frame %d, Physical Address
%d\n",
logicalAddress, pageNumber, pageOffset, frameNumber, physicalAddress);
}
}
}
OUTPUT:
Simulating Paging Technique:
Logical Address -> Physical Address
Logical Address 5: Page 1, Offset 1 -> Frame 1, Physical Address 5
Logical Address 8: Page 2, Offset 0 -> Frame 4, Physical Address 16
Logical Address 14: Page 3, Offset 2 -> Frame 2, Physical Address 14
Logical Address 18: Invalid (Page number 4 out of range)
Logical Address 2: Page 0, Offset 2 -> Frame 3, Physical Address 14
Logical Address 9: Page 2, Offset 1 -> Frame 4, Physical Address 17

11) Implement Bankers Algorithm for Dead Lock avoidance and prevention

Write a C Program to implement Bankers Algorithm for Deadlock Prevention


#include<stdio.h>
#include<conio.h>
void main()
{
int allocated[15][15],max[15][15],need[15][15],avail[15],tres[15],work[15],flag[15]; int
pno,rno,i,j,prc,count,t,total;
count=0;
printf("\n Enter number of process:"); scanf("%d",&pno);
printf("\n Enter number of resources:"); scanf("%d",&rno);
for(i=1;i<=pno;i++)
{
flag[i]=0;

}
printf("\n Enter total numbers of each resources:"); for(i=1;i<= rno;i++)
scanf("%d",&tres[i]);
printf("\n Enter Max resources for each process:"); for(i=1;i<= pno;i++)
{
printf("\n for process %d:",i); for(j=1;j<= rno;j++) scanf("%d",&max[i][j]);
}
printf("\n Enter allocated resources for each process:"); for(i=1;i<= pno;i++)
{
printf("\n for process %d:",i); for(j=1;j<=rno;j++) scanf("%d",&allocated[i][j]);
}
printf("\n available resources:\n"); for(j=1;j<= rno;j++)
{
avail[j]=0; total=0;
for(i=1;i<=pno;i++)
{
total+=allocated[i][j];
}
avail[j]=tres[j]-total; work[j]=avail[j]; printf(" %d\t",work[j]);
}
do{ for(i=1;i<=pno;i++)
{
for(j=1;j<=rno;j++)
{
need[i][j]=max[i][j]-allocated[i][j];
}
}
printf("\n Allocated matrix Max need"); for(i=1;i<=pno;i++)
{
printf("\n"); for(j=1;j<=rno;j++)
{
printf("%4d",allocated[i][j]);
}
printf("|"); for(j=1;j<=rno;j++)
{
printf("%4d",max[i][j]);
}
printf("|"); for(j=1;j<=rno;j++)
{
printf("%4d",need[i][j]);
}
}
prc=0; for(i=1;i<=pno;i++)
{
if(flag[i]==0)
{
prc=i; for(j=1;j<=rno;j++)
{
if(work[j]<need[i][j])
{
prc=0; break;
}
}
}
if(prc!=0)

break;
}
if(prc!=0)
{
printf("\n Process %d completed",i); count++;
printf("\n Available matrix:"); for(j=1;j<=rno;j++)
{
work[j]+=allocated[prc][j]; allocated[prc][j]=0; max[prc][j]=0; flag[prc]=1;
printf(" %d",work[j]);
}
}
}
while(count!=pno&&prc!=0); if(count==pno)
printf("\nThe system is in a safe state!!"); else
printf("\nThe system is in an unsafe state! ");
}
Enter number of process:5 Enter number of resources:3
Enter total numbers of each resources:10
5
7
Enter Max resources for each process: for Process1:7
5
3
for process 2:3
2
2
for process 3:2
2
2
for process 4:9
0
2
for process 5:4
3
3
Enter allocated resources for each process: for process 1:0
1
0
for process 2:3
0
2
for process 3:3
0
2
for process 4:2
1
1
for process 5:0
0
2
available resources: 2 3 0
Allocated matrix Max need

0 1 0| 7 5 3| 7 4 3
3 0 2| 3 2 2| 0 2 0
3 0 2| 2 2 2| -1 2 0
2 1 1| 9 0 2| 7 -1 1
0 0 2| 4 3 3| 4 3 1
Process 2 completed
Available matrix: 5 3 2 Allocated matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
3 0 2| 2 2 2| -1 2 0
2 1 1| 9 0 2| 7 -1 1
0 0 2| 4 3 3| 4 3 1
Process 3 completed
Available matrix: 8 3 4 Allocated matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
2 1 1| 9 0 2| 7 -1 1
0 0 2| 4 3 3| 4 3 1
Process 4 completed
Available matrix: 10 4 5 Allocated matrix Max need
0 1 0| 7 5 3| 7 4 3
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
00 2| 4 3 3| 4 3 1
Process 1 completed
Available matrix: 10 5 5 Allocated matrix Max need
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 0| 0 0 0| 0 0 0
0 0 2| 4 3 3| 4 3 1
Process 5 completed
Available matrix: 10 5 7 The system is in a safe state!!
Process exited after 137 seconds with return value 32 Press any key to continue .
12)Simulate the following file allocation strategies
a) Sequential b) Indexed c) Linked
a) Sequential Allocation:
#include <stdio.h>
#include <stdlib.h>
#define MAX_BLOCKS 10:
int disk[MAX_BLOCKS] = {0};
void sequentialAllocation(int fileSize) {
int blocksRequired = fileSize;
printf("\nSequential Allocation:\n");
// Find contiguous free blocks for the file
for (int i = 0; i < MAX_BLOCKS && blocksRequired > 0; i++) {
if (disk[i] == 0) { // If the block is free
disk[i] = 1; // Allocate the block
blocksRequired--;
printf("Block %d allocated\n", i);
}
}

if (blocksRequired > 0)
{
printf("Not enough space for the file.\n");
} else {
printf("File allocated successfully.\n");
}
}

int main()
{
int fileSize;
printf("Enter the file size for sequential allocation (number of blocks): ");
scanf("%d", &fileSize);
sequentialAllocation(fileSize);
return 0;
}
OUTPUT:
Enter the file size for sequential allocation (number of blocks): 5
Sequential Allocation:
Block 0 allocated
Block 1 allocated
Block 2 allocated
Block 3 allocated
Block 4 allocated
File allocated successfully.

b) Indexed Allocation:
#include <stdio.h>
#include <stdlib.h>
#define MAX_BLOCKS 10
#define MAX_FILE_SIZE 5

int disk[MAX_BLOCKS] = {0};


int indexBlock[MAX_FILE_SIZE] = {-1};
void indexedAllocation(int fileSize)
{
int blocksRequired = fileSize;
int indexPointer = 0;
printf("\nIndexed Allocation:\n");
for (int i = 0; i < MAX_BLOCKS && blocksRequired > 0; i++)
{
if (disk[i] == 0) { // If block is free
disk[i] = 1; // Allocate the block
indexBlock[indexPointer++] = i; // Store the block's index in the index block
blocksRequired--;
printf("Block %d allocated at index %d\n", i, indexPointer - 1);
}
}

if (blocksRequired > 0)
{
printf("Not enough space for the file.\n");
} else {
printf("File allocated successfully.\n");
}
}

int main()
{
int fileSize;
printf("Enter the file size for indexed allocation (number of blocks): ");
scanf("%d", &fileSize);

indexedAllocation(fileSize);

return 0;
}
OUTPUT:
Enter the file size for indexed allocation (number of blocks): 4

Indexed Allocation:
Block 0 allocated at index 0
Block 1 allocated at index 1
Block 2 allocated at index 2
Block 3 allocated at index 3
File allocated successfully.

C) Linked Allocation:
#include <stdio.h>
#include <stdlib.h>
#define MAX_BLOCKS 10 // Number of available blocks in the disk
int disk[MAX_BLOCKS] = {0};
int nextBlock[MAX_BLOCKS];
void linkedAllocation(int fileSize)
{
int blocksRequired = fileSize;
int firstBlock = -1, prevBlock = -1;
printf("\nLinked Allocation:\n");

// Initialize the nextBlock array to -1 (indicating no links)


for (int i = 0; i < MAX_BLOCKS; i++)
{
nextBlock[i] = -1;
}
// Allocate blocks for the file
for (int i = 0; i < MAX_BLOCKS && blocksRequired > 0; i++)
{
if (disk[i] == 0) { // If the block is free
disk[i] = 1; // Allocate the block
if (firstBlock == -1)
{
firstBlock = i; // Set the first block
printf("File starts at block %d\n", firstBlock);
}

if (prevBlock != -1)
{
nextBlock[prevBlock] = i;
printf("Block %d linked to block %d\n", i, prevBlock);
}

prevBlock = i;
blocksRequired--;
}
}

if (blocksRequired > 0)
{
printf("Not enough space for the file.\n");
}
Else
{
printf("File allocated successfully.\n");
}
}

int main()
{
int fileSize;

printf("Enter the file size for linked allocation (number of blocks): ");
scanf("%d", &fileSize);
linkedAllocation(fileSize);
return 0;
}
OUTPUT:
Enter the file size for linked allocation (number of blocks): 3
Linked Allocation:
File starts at block 0
Block 1 linked to block 0
Block 2 linked to block 1
File allocated successfully.

13)Download and install Nachos operating system and experiment with it.
Downloading Nachos

1. Visit the Nachos website: Go to the official Nachos website ((link unavailable)) and click on
the "Releases" tab.
2. Download the Nachos source code: Click on the latest release (e.g., "Nachos-6.0") and
download the source code zip file (e.g., "nachos-6.0.zip").
3. Extract the source code: Extract the contents of the zip file to a directory on your
computer (e.g., C:\nachos or ~/nachos).

Installing Nachos

1. Install a C++ compiler: Nachos requires a C++ compiler to build. Install a C++ compiler such
as GCC (GNU Compiler Collection) or Clang.
2. Install the Nachos dependencies: Nachos requires several dependencies, including make
and gcc. Install these dependencies using your package manager (e.g., apt-get on Ubuntu or
brew on macOS).
3. Build Nachos: Navigate to the Nachos directory and run the make command to build
Nachos.

Running Nachos
1. Run Nachos: After building Nachos, run the nachos command to start the operating
system.
2. Explore the Nachos shell: Once Nachos is running, you'll see a shell prompt. You can use
this shell to explore the Nachos file system, run commands, and execute programs.

Experimenting with Nachos

1. Run Nachos programs: Nachos comes with several example programs, such as hello.c and
sort.c. Run these programs using the nachos command.
2. Write your own Nachos programs: Try writing your own programs in C++ and compiling
them for Nachos.
3. Experiment with Nachos system calls: Nachos provides several system calls, such as Create
and Open. Experiment with these system calls to learn more about how Nachos works.
4. Modify the Nachos source code: Try modifying the Nachos source code to add new
features or fix bugs.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy