×
It does not matter how slowly you go as long as you do not stop.
--Your friends at LectureNotes
Close

Operating Systems

by Anna Superkings
Type: PracticalInstitute: ANNA UNIVERISTY Specialization: Information Technology EngineeringOffline Downloads: 2Views: 50Uploaded: 2 months agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Anna Superkings
Anna Superkings
CS6431 - OPERATING SYSTEMS LAB SEMESTER-IV LIST OF EXPERIMENTS 1. Basics of UNIX commands. 2. Shell programming 3. Implementation of CPU scheduling. a) Round Robin b) SJF c) FCFS d) Priority 4. Implement all file allocation strategies i) Indexed ii) Linked 5. Implement Semaphores 6. Implement all File Organization Techniques a) Single level directory b) Two level c) Hierarchical d) DAG 7. Implement Bankers Algorithm for Dead Lock Avoidance 8. Implement an Algorithm for Dead Lock Detection 9. Implement the all page replacement algorithms a) FIFO b) LRU c) LFU 10.Implement Shared memory and IPC 11.Implement Paging Technique of memory management. 12.Implement Threading & Synchronization Applications 2
EX.NO : 1) BASICS OF UNIX COMMANDS. i) PROGRAM USING SYSTEM CALL fork() AIM : To write the program to create a Child Process using system call fork(). ALGORITHM : Step 1 : Declare the variable pid. Step 2 : Get the pid value using system call fork(). Step 3 : If pid value is less than zero then print as “Fork failed”. Step 4 : Else if pid value is equal to zero include the new process in the system‟s file using execlp system call. Step 5 : Else if pid is greater than zero then it is the parent process and it waits till the child completes using the system call wait() Step 6 : Then print “Child complete”. SYSTEM CALLS USED: 1. fork( ) Used to create new processes. The new process consistsof a copy of the address space of the original process. The value of process id for the child process is zero, whereas the value of process id for the parent is an integer value greater than zero. Syntax : fork( ) 2.execlp( ) Used after the fork() system call by one of the two processes to replace the process‟ memory space with a new program. It loads a binary file into memory destroying the memory image of the program containing the execlp system call and starts its execution.The child process overlays its address space with the UNIX command /bin/ls using the execlp system call. Syntax : execlp( ) 3. wait( ) The parent waits for the child process to complete using the wait system call. The wait system call returns the process identifier of a terminated child, so that the parent can tell which of its possibly many children has terminated. Syntax : wait( NULL) 4. exit( ) A process terminates when it finishes executing its final statement and asks the operating system to delete it by using the exit system call. At that point, the process may return data (output) to its parent process (via the wait system call). Syntax: exit(0) PROGRAM CODING : #include<stdio.h> #include<stdlib.h> #include<unistd.h> void main(int argc,char *arg[]) { int pid; 3
pid=fork(); if(pid<0) { printf("fork failed"); exit(1); } else if(pid==0) { execlp("whoami","ls",NULL); exit(0); } else { printf("\n Process id is -%d\n",getpid()); wait(NULL); exit(0); } } OUTPUT: [cse6@localhost Pgm]$ cc prog4a.c [cse6@localhost Pgm]$ ./a.out RESULT: Thus the program was executed and verified successfully 4
EX.NO : 1)ii) PROGRAM USING SYSTEM CALLS getpid() & getppid() AIM : To write the program to implement the system calls getpid() and getppid(). ALGORITHM : Step 1 : Declare the variables pid , parent pid , child id and grand chil id. Step 2 : Get the child id value using system call fork(). Step 3 : If child id value is less than zero then print as “error at fork() child”. Step 4 : If child id !=0 then using getpid() system call get the process id. Step 5 : Print “I am parent” and print the process id. Step 6 : Get the grand child id value using system call fork(). Step 7 : If the grand child id value is less than zero then print as “error at fork() grand child”. Step 8 : If the grand child id !=0 then using getpid system call get the process id. Step 9 : Assign the value of pid to my pid. Step 10 : Print “I am child” and print the value of my pid. Step 11 : Get my parent pid value using system call getppid(). Step 12 : Print “My parent‟s process id” and its value. Step 13 : Else print “I am the grand child”. Step 14 : Get the grand child‟s process id using getpid() and print it as “my process id”. Step 15 : Get the grand child‟s parent process id using getppid() and print it as “my parent‟s process id SYSTEM CALLS USED : 1.getpid( ) Each process is identified by its id value. This function is used to get the id value of a particular process. 2.getppid( ) Used to get particular process parent‟s id value. 3.perror( ) Indicate the process error. PROGRAM CODING: #include<stdio.h> #include<unistd.h> #include<stdlib.h> int main( ) { int pid; pid=fork( ); if(pid== -1) { 5

Lecture Notes