OPERATING SYSTEMS LAB Subject Code: 21CSC202J B.TECH II Year / III Semester NAME-WAQUAS ARSHAD REG.No.- RA2211003030319 DEPARTMENT OF COMPUTER SCIENCE ENGINEERING SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR CAMPUS, MODINAGAR SIKRI KALAN, DELHI MEERUT ROAD, DIST. GHAZIABAD, 201204. Odd Semester (July-Dec,2023) SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR CAMPUS, MODINAGAR BONAFIDE CERTIFICATE Certified to be the bonafide record of work done by Waquas Arshad Reg.No. RA2211003030319 Of IIIrd semester IInd year B.TECH degree course in SRM INSTITUTE OFSCIENCE & TECHNOLOGY, DELHI-NCR Campus for the Department of Computer Science & Engineering, in Operating Systems Laboratory duringthe academic year 2023-2024. Lab In charge Submitted for End Semester examination held on Head of the Department / / at SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR Campus. Internal Examiner-I Internal Examiner-II SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR CAMPUS, MODINAGAR INDEX S.No. Name of Experiment Date of Date of Signature Execution Submission 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR CAMPUS, MODINAGAR 21CSC202J - Operating Systems Lab Exp. No. 1 a) Basics 1. echo SRM BASIC LINUX COMMANDS to display the string SRM 2. clear to clear the screen 3. date to display the current date and time 4. cal 2003 cal 6 2003 to display the calendar for the year 2003 to display the calendar for the June-2003 5. passwd to change password b) Working with Files 1. 1s list files in the present workingdirectory 1s —1 list files with detailed information (long list) 1s —a list all files including the hidden files 2. cat > fl 3. cat R © SRMIST to create a file (Press ^d to finish typing) display the content of the file f1 Date : 21CSC202J - Operating Systems Lab 4. wc fl wc -c fl wc -w fl wc -l fl list no. of characters, words & lines of a file fl list only no. of characters of filefl list only no. of words of file f1 list only no. of lines of file fl 5. cp fl f2 copy file fl into f2 6. mv fl f2 rename file fl as f2 7. rm R remove the file f1 8. head -5fl tail -5fl list first 5 lines of the file fl list last 5 lines of the file fl c) Working with Directories 1. mkdir elias to create the directory elias 2. cd elias to change the directory as elias 3. rmdir elias to remove the directory elias to display the path of the present working directory 4. pwd 5. cd cd .. cd cd/ © SRMIST to go to the home directory to go to the parent directory to go to the previous working directory to go to the root directory 21CSC202J - Operating Systems Lab d) File name substitution 1. 1s f? list files start with ‘fi and followed by any one character 2. 1s *.c list files with extension ‘c’ 3. 1s [gpy]et list files whose first letter is any one of the character g, p or y and followed by the word et 4. 1s [a-d,l-m]ring list files whose first letter is any one of the character from a to d and 1 to m and followed by the word ring. © SRMIST 6- Exp. No. 2 Process Creation using fork() and usage of getpid(), getppid(), wait()functions Date: 1) fork(): The fork() command is a system call in Unix-based OS that creates a new process by duplicating the calling process. The new process is an exact copy of the parent process, with its own address space and memory. Program: #include <stdio.h> #include<sys/types.>; #include<unistd.h>; int main() { // make two process which run same // program after this instructionfork(); printf("Hello world!\n");return 0; } 2) getppid() : Returns the process ID of the parent of the calling process. If the calling process was created by the fork() function and the parent process still exists at the time of the getppid function call, this function returns the process ID of the parent process. Otherwise, this function returns a value of 1 which is the process id for init process. Return type: getppid() returns the process ID of the parent of the current process. It never throws any error therefore is always successful. getpid() : returns the process ID of the calling process. This is often used by routines that generate unique temporary filenames. Return type: getpid() returns the process ID of the current process. It never throws any error therefore is always successful. Program: #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { pid_t p; p = fork(); if(p==-1) { printf("There is an error while calling fork()\n"); } if(p==0) { printf("We are in the child process\n"); } else { printf("We are in the parent process\n"); } return 0; } 3) wait() system call. wait() system call will force a parent process to wait for a child process to stop or terminate. wait() system call return the pid of the child or -1 for an error. Syntax of wait system call: int wait(int *status_location) waitpid() system call is used to wait on particular child process instead of waiting for all the child process. Syntax for waitpid(): pid_t waitpid(pid_t pid, int *statloc, int options); Program: #include <stdio.h> #include<stdlib.h> #include<sys/types.> #include<sys/wait.h> #include <unistd.h> //#include <unistd.h> int main() { pid_t pid=fork(); if(pid==0) { printf("child => PPID: %d PID: %d\n", getppid(), getpid()); sleep(6); exit(EXIT_SUCCESS); } else if(pid > 0) { printf("parent => PID: %d\n", getpid()); printf("waiting for child process to finish \n"); wait(NULL); printf("child process finished \n"); } else { printf("unable to create child process\n"); } return EXIT_SUCCESS; }