Docsity

Operating system practical file du, Assignments of Operating Systems

Toggle sidebar
bg1
OPERATING SYSTEM
KANCHAN SAGAR
20/CS/21
SEM = 3rd
PRACTICAL FILE
Q1) // C program to illustrate use of fork() &
// exec() system call for process creation
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
int main(){
pid_t pid;
int ret = 1;
int status;
pid = fork();
if (pid == -1){
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32

Partial preview of the text

Download Operating system practical file du and more Assignments Operating Systems in PDF only on Docsity!

OPERATING SYSTEM

KANCHAN SAGAR

20/CS/

SEM = 3

rd

PRACTICAL FILE

Q1) // C program to illustrate use of fork() & // exec() system call for process creation #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> #include <sys/wait.h> int main(){ pid_t pid; int ret = 1; int status; pid = fork(); if (pid == -1){

// pid == -1 means error occured printf("can't fork, error occured\n"); exit(EXIT_FAILURE); } else if (pid == 0){ // pid == 0 means child process created // getpid() returns process id of calling process // Here It will return process id of child process printf("child process, pid = %u\n",getpid()); // Here It will return Parent of child Process means Parent process it self printf("parent of child process, pid = %u\n",getppid()); // the argv list first argument should point to // filename associated with file being executed // the array pointer must be terminated by NULL // pointer char * argv_list[] = {"ls","-lart","/home",NULL}; // the execv() only return if error occured. // The return value is - execv("ls",argv_list); exit(0); }

printf("execv failed\n"); } else printf("program terminated normally," " but returned a non-zero status\n"); } else printf("program didn't terminate normally\n"); } else { // waitpid() failed printf("waitpid() failed\n"); } exit(0); } return 0; }

Q2) #include<stdio.h> #include<stdlib.h> int main() { printf("### Kernel Information ###\n\n"); system("cat /proc/version_signature | awk '{printf "Kernel Version: %s\n", $0}'"); printf("\n### CPU Information ###\n\n"); system("cat /proc/cpuinfo | awk '/processor|model/{print}'"); return 0; } Q3) #include<stdio.h> #include<stdlib.h> int main() { system("clear"); printf("First version \ncpu model \n"); system("cat /proc/cpuinfo |awk 'NR==5{print}' "); printf("kernel version \n"); system("cat /proc/version"); printf("\nAmount of time lastn booted \n"); system("cat /proc/uptime"); printf("Amount of memory configured in the system.\n"); system("cat /proc/meminfo |awk 'NR==4{print}'");

Q4) #include #include<sys/stat.h> using namespace std; int main(int argc, char*argv[]){ int i; struct stat buffer; if(argc<2){ cout<<"USAGE
n"<<argv[1]; } for(i=1;i<argc;i++){ cout<<"\nFILE NAME IS = "; cout<< argv[i]<<endl; if(stat(argv[i], &buffer)<0){

cout<<"ERROR IN OBTAINING FILE STATS\n"; } else{ cout<<"\nOWNER USER ID, UID = "<<buffer.st_uid<<"\n\nGROUP ID, GID = "<<buffer.st_gid<<endl; cout<<"\nACCESS PERMISSION = "<<buffer.st_mode<<endl; cout<<"\nACCESS TIME = "<<buffer.st_atime<<"\n"; } } return(0); } Output: Q5) // C++ program for implementation of RR scheduling #include using namespace std; // Function to find the waiting time for all // processes void findWaitingTime(int processes[], int n,

if (rem_bt[i] > quantum) { // Increase the value of t i.e. shows // how much time a process has been processed t += quantum; // Decrease the burst_time of current process // by quantum rem_bt[i] -= quantum; } // If burst time is smaller than or equal to // quantum. Last cycle for this process else { // Increase the value of t i.e. shows // how much time a process has been processed t = t + rem_bt[i]; // Waiting time is current time minus time // used by this process wt[i] = t - bt[i];

// As the process gets fully executed // make its remaining burst time = 0 rem_bt[i] = 0; } } } // If all processes are done if (done == true) break; } } // Function to calculate turn around time void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) { // calculating turnaround time by adding // bt[i] + wt[i] for (int i = 0; i < n ; i++) tat[i] = bt[i] + wt[i]; } // Function to calculate average time

cout << "Average waiting time = " << (float)total_wt / (float)n; cout << "\nAverage turn around time = " << (float)total_tat / (float)n; } // Driver code int main() { // process id's int processes[] = { 1, 2, 3}; int n = sizeof processes / sizeof processes[0]; // Burst time of all processes int burst_time[] = {10, 5, 8}; // Time quantum int quantum = 2; findavgTime(processes, n, burst_time, quantum); return 0; }

Q6) // C++ program for implementation of FCFS // scheduling #include using namespace std; // Function to find the waiting time for all // processes void findWaitingTime(int processes[], int n, int bt[], int wt[]) { // waiting time for first process is 0 wt[0] = 0; // calculating waiting time

//Function to find waiting time of all processes findWaitingTime(processes, n, bt, wt); //Function to find turn around time for all processes findTurnAroundTime(processes, n, bt, wt, tat); //Display processes along with all details cout << "Processes "<< " Burst time " << " Waiting time " << " Turn around time\n"; // Calculate total waiting time and total turn // around time for (int i=0; i<n; i++) { total_wt = total_wt + wt[i]; total_tat = total_tat + tat[i]; cout << " " << i+1 << "\t\t" << bt[i] <<"\t "

<< wt[i] <<"\t\t " << tat[i] <<endl; } cout << "Average waiting time = " << (float)total_wt / (float)n; cout << "\nAverage turn around time = " << (float)total_tat / (float)n; } // Driver code int main() { //process id's int processes[] = { 1, 2, 3}; int n = sizeof processes / sizeof processes[0]; //Burst time of all processes int burst_time[] = {10, 5, 8};

float atat=0,awt=0,stat=0,swt=0; cout<<"enter no of process"<<endl; cin>>n; int a[n],b[n],e[n],tat[n],wt[n]; for(i=0;i<n;i++) { cout<<"enter arival time "; //input cin>>a[i]; } for(i=0;i<n;i++) { cout<<"enter brust time "; //input cin>>b[i]; } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(b[i]>b[j]) { temp=a[i]; a[i]=a[j];

a[j]=temp; temp=b[i]; b[i]=b[j]; b[j]=temp; } } } min=a[0]; for(i=0;i<n;i++) { if(min>a[i]) { min=a[i]; d=i; } } tt=min; e[d]=tt+b[d]; tt=e[d]; for(i=0;i<n;i++) { if(a[i]!=min)