Posts

Showing posts from February, 2024

CSL 204 OPERATING SYSTEM LAB KTU IV SEM CSE

About Me Syllabus Scheme Program List Linux Basics 1. Linux History and GNU 2. Linux Basic Features and Architecture 3. How to Install Linux 4. Install Linux Inside Windows using WSL 5. Free software 6. Linux Chronology 7 .Package Management 8 .Compile and install from source 9 .Important Directories 10. File Permissions 11. Special Permissions 12 .Shell 13. Bash shell in windows 10 14 .Basic Linux command for beginners 15. Input Output Redirection  16. Directory Commands 17. File Commands 18 .Communication Commands 19. Information Commands  20 .IO Commands   21 .Process Management Commands 22. Account Administration Commands 23. Pipes and Filters  24. Top 100 commands to learn. Shell Programming 1. Shell Script 2. Arithmetic Expressions 3. Special Shell Variables 4. Shell Script for getting important info 5. if and case statement 6. looping statements while,until,for 7. Menu driven Programs 8. GUI Menus 9. Functions in scripts 10. String Handling 11. Command line arguments in scripts

Questions

OPERATING SYSTEMS LAB - PRACTICE QUESTIONS 1. Write a program to create a process in linux. 2. Write programs using the following system calls of Linux operating system: fork, exec, getpid, exit, wait, close, stat, opendir, readdir 3. Write programs using the I/O system calls of Linux operating system (open, read, write) 4. Given the list of processes, their CPU burst times and arrival times, display/print the Gantt chart for FCFS and SJF. For each of the scheduling policies, compute and print the average waiting time and average turnaround time 5. Write a C program to simulate following non-preemptive CPU scheduling algorithms to find turnaround time and waiting time. a)FCFS b) SJF c) Round Robin (pre-emptive) d) Priority 6. Write a C program to simulate following contiguous memory allocation techniques a) Worst-fit b) Best-fit c) First-fit 7. Write a C program to simulate paging technique of memory management. 8. Write a C program to simulate Bankers algorithm for the purpose of dead

Syllabus - CST 204 OPERATING SYSTEM LAB

SYLLABUS OPERATING SYSTEMS LAB 1. Basic Linux commands 2. Shell programming -Command syntax -Write simple functions with basic tests, loops, patterns 3. System calls of Linux operating system:* fork, exec, getpid, exit, wait, close, stat, opendir, readdir 4. Write programs using the I/O system calls of Linux operating system (open, read, write) 5. Implement programs for Inter Process Communication using Shared Memory * 6. Implement Semaphores* 7. Implementation of CPU scheduling algorithms. a) Round Robin b) SJF c) FCFS d) Priority * 8. Implementation of the Memory Allocation Methods for fixed partition* a) First Fit b) Worst Fit c) Best Fit 9. Implement l page replacement algorithms a) FIFO b) LRU c) LFU* 10. Implement the banker’s algorithm for deadlock avoidance. * 11. Implementation of Deadlock detection algorithm 12. Simulate file allocation strategies. b) Sequential b) Indexed c) Linked 13. Simulate disk scheduling algorithms. * c) FCFS b)SCAN c) C-SCAN * mandatory

Scheme - CST 204 Operating System Lab

 

Shell script for important info

 Show Currently logged  users  ( w or who -H)      Show only the user name of logged users in the host  ( users)      Details of last login  ( last mec  ;where mec is the user id )  About your OS and version, release number, kernel version                                                  ( uname -a or  cat  /proc/version)  Show all available shells  ( cat /etc/shells )  Show mouse settings  (cat  /sys/class/input/mouse*/device/name )  Show computer CPU information       CPU details       ( cat /proc/cpuinfo | more )       Show information on  CPU architecture  ( lscpu)       Number of Processor core  ( nproc)  Show memory information       Memory details  ( cat /proc/meminfo | more )       Display file system disk usage  ( df -h )       Display the amount of free and used memory  ( free)        Virtual memory statistics  ( vmstat)  File system Mounted  ( findmnt or cat /proc/mounts) Note: There are some advanced command like  lshw  which will list complete hardware details.  The

Shell Variables

  Write shell scripts to show the following  ( you can write menu driven programs)  Currently logged user and his logname    ( logname, id -un, echo $USER)  Your current shell (  echo $SHELL)  Your home directory  ( echo $HOME)  Your operating system type  (echo $OSTYPE)  Your current path setting  ( echo $PATH)  Your current working directory  ( echo $PWD )

Top 100 commands to learn

clear- Clear the screen cd — Change directory ls — List directory contents pwd — Print working directory cat — Concatenate and display files touch — Create an empty file cp — Copy files and directories mv — Move or rename files and directories rm — Remove files and directories mkdir — Create a new directory rmdir — Remove an empty directory cut — Cut out sections of a file gzip — Compress or decompress files using gzip gunzip — Decompress files compressed with gzip find — Find files and directories matching a pattern grep — Search for a pattern in a file awk — Pattern scanning and processing language sed — Stream editor for filtering and transforming text head — Display the first few lines of a file tail — Display the last few lines of a file sort — Sort lines of a file uniq — Remove duplicate lines from a file wc — Count lines, words, and characters in a file diff — Compare two files line by line chmod — Change permissions of files and directories chown — Change the owner of a file or

Assignment-4 Learn to Write Advanced Scripts

1.Create a script that accepts a filename as input and checks if it exists. 2.List the empty files in the current directory. 3.Write a script to copy files from one directory to another.(backup files) 4.Develop a script to delete all files with a specific extension in a directory.(cleaning up) 5..List the name,file size of ordinary files( avoid directories) in the current directory in the descending order of file size. ( Hint:Use tr,grep,tail,cut and sort command) 6.Display the contents of the smallest file( file size is lowest) 7.List the pid(process id), start time and process (command) of all running process.( Hint: use ps –aux command) 8.List the details of the process with process id 1.(Hint use ps command and grep) 9.List the permissions of user and file name of ordinary files in the current directory( avoid directories). (hint use grep, tr –s,cut –c ,paste. Cut the required fields and store in temporary files.Paste them together using paste.) 10.List the directories only with pe

Assignment-2 Learn Control Statements

  Learn Control Statements- Write the shell scripts 1.Check whether the number is even or odd(if else) 2. Check the quadrant of a given point(x,y) ( if else with multiple conditions) 3. Find the biggest of 3 numbers ( if elif) 4.Enter  a month number and print its name( case) 5. Check whether the given number is prime or not ( while) 6.Find sum of the digits of a number.(  until) 7.Print all odd numbers less than 50. (  for) 8.Print all the words and its length from a file f. (  for) 9.Check whether the given string is palindrome.(string functions) 10.Print palindrome words from a file(nested loops - for ) 11.Print all prime numbers less than 100 ( nested loop -while) 12.Print the words starting with letter ‘a’ in sorted order from a file f.( Hint:use for loop to extract words and write it to another file. Use sort command to sort and then use grep command to extract words starting with letter ‘a’) Note: We do these programs to learn the syntax of control stateme

Assignment-1 Simple Shell Scripts

  Write shell scripts to show the following ( you can write menu driven programs) 1. a)Display the date and time b)Current month calendar c)contents of the home directory of a user 2. a)Currently logged user and his logname b) Your current shell c) Your home directory 3. a)Your operating system type b) Your current path setting c) Your current working directory . 4. a)Show Currently logged users b)Show only the user name of logged users in the host. c)Details of last login 5. a) About your OS and version, release number, kernel version b) Show all available shells c) Show mouse settings 6. a)CPU details b) Show information on CPU architecture c)Number of Processor core 7. a)Memory details b) Display file system disk usage c)Display the amount of free and used memory d)Virtual memory statistics e) File system Mounted Write shell scripts 1. Menu ( GUI) driven program to display long listing of files in the current directory ( ls –l) list of users currently logged in

Assignment-3 Learn Filter Commands and Data Processing

  Write shell scripts to do the following on a “stud” data file which contains rno,name,dob ( date of birth),m1,m2,m3 ( mark in three subjects out of 50). Create the “stud” file in the following format using any editor. 101|hari | 06-05-1985|30|40|35 102|devi | 03-08-1982|40|35|28 ................................................................add more data in the same format ( you can write menu driven programs) 1. ( Hint :Use sort command ) a) List the students in the order of roll number b) list the students in the order of name c) list the students in the order of year of birth 2.( Hint: Use cut command ) a) List the roll number and name of all students. b) List the roll number, name and m3. c) List roll number, name and dob of all students. 3.(Hint :use cut ,and sort command) a) List roll number, name m1 in the descending order of m1. b)List the roll number , name and m2 of the top 5 performers in subject 2. ( use head) c)List the roll number , name and m3

fork

The fork() function in C is used for creating a new process in Linux and Unix systems. It allows you to create a child process that runs concurrently with the process that makes the fork() call (which is the parent process).  Here’s the basic syntax: #include <unistd.h>   pid_t fork(void); The unistd.h header file, commonly used in C and C++ programming languages, provides access to the POSIX operating system API. Let’s break down its significance: Definition and Purpose: unistd.h stands for “Unix Standard Header”. It serves as a bridge between your program and the underlying operating system, enabling interaction with system resources and services. The header file contains function prototypes, macros, and constants that allow your program to communicate with the operating system. Functionality:The interface defined by unistd.h includes various system call wrapper functions and I/O primitives. Some notable functions and features provided by unistd.h: fork: Creates a new process

I/O Operations Reading/writing Files

Let’s explore how to perform file I/O using system calls in Linux. We’ll cover creating, opening, reading, writing, and closing files using low-level system calls. Creating a New File: To create a new file, you can use the open() system call. Syntax:       int open(const char *pathname, int flags, mode_t mode); Parameters:      pathname: The path to the file you want to create.      flags:Flags specifying the file access mode (e.g., O_CREAT | O_WRONLY for write-only).      mode: Permissions for the new file (e.g., 0644 for read-write permissions for the owner and read-only                     permissions for others). Example: #include <fcntl.h>  #include <stdio.h>  #include <stdlib.h>   int main()  { const char *filename = "new_file.txt";   int fd = open(filename, O_CREAT | O_WRONLY, 0644);   if (fd == -1)       { perror("Error creating file");         exit(EXIT_FAILURE); }       printf("File '%s' created successfully.\n", file

Reading The File Status

The important steps in Reading the file status Open the File: Use the fopen() function to open the file in read mode. The file path and mode (e.g., "r") are required parameters. Read File Properties: Use the stat() function to retrieve information about the file. The stat structure contains details such as file size, permissions, creation time, and modification time. Print File Properties: Extract relevant information from the stat structure. Print details like file size, creation date, and modification date.  #include <stdio.h> #include <sys/stat.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <time.h> int main() { char filename[50]; struct stat fileStat; printf("Enter the filename:"); scanf("%s",filename); // Call stat() to get file status if (stat(filename, &fileStat) == -1) { perror("Error"); return 1; } printf("Information for %s\n",filename); printf("-------------

Reading Directory Contents

opendir(), readdir(), and closedir(): These functions are used for directory traversal.      opendir(): Opens a directory stream.      readdir(): Reads the next directory entry (file or subdirectory).      closedir(): Closes the directory stream. Example: #include <dirent.h>  #include <stdio.h>   int main()  {   DIR *dir = opendir(".");   if (dir) {  struct dirent *entry;   printf("Current Directory Contents\n");  while ((entry = readdir(dir)) != NULL)  {   printf("%s\n", entry->d_name);   }   closedir(dir); }   return 0;  }

fork and exec

fork() The fork() system call creates a new process by duplicating the address space of the calling process. The new process, called the child process, is an exact copy of the parent process except for a few differences (e.g., unique process ID). The return value of fork() is:      In the parent process: The child’s process ID (PID).      In the child process: 0.      On failure: -1 (no child process is created). exec(): The exec() family of functions replaces the current process image with a new one. It loads the specified program into the current process space and runs it from the entry point. The most commonly used exec() functions include: execv: The execv function takes the program name and an array of pointers to null-terminated strings that represent the argument vector, similar to the argv parameter in the main function. int execv(const char *path, char *const argv[]); execvp: The execvp function is similar to execv, but it searches for the executable file using the directori

Priority Scheduling

Image
Priority Scheduling is a CPU scheduling algorithm where processes are assigned priorities, and the process with the highest priority is selected for execution. Let’s delve into the details: Priority Assignment: Each process is assigned a numerical priority value. Lower numbers indicate higher priority (i.e., process with priority 1 has the highest priority). Priority can be based on various factors such as memory requirements, time constraints, importance, etc Types of Priority Scheduling: Preemptive Scheduling: In preemptive priority scheduling, tasks are assigned priorities. If a higher-priority task arrives while a lower-priority task is running, the lower-priority task is preempted, and the higher-priority task starts executing. Example: Real-time systems where critical tasks need immediate attention. Non-Preemptive Scheduling: In non-preemptive priority scheduling, the CPU is allocated to a specific process. The process that holds the CPU continues until it releases it (e.g., by c

Round Robin Scheduling

Image
Round Robin is a preemptive CPU scheduling algorithm used in multitasking operating systems. It ensures that each process gets a fair share of the CPU time by allowing them to run in a cyclic queue for a fixed time slice called the time quantum.    The Round Robin (RR) CPU scheduling algorithm is one of the most common algorithms used in operating systems to manage the execution of processes. It's designed to provide fair allocation of CPU time to all processes in the system. Here's how it works: Queue: The ready queue contains all the processes that are ready to execute. In Round Robin, this queue is typically implemented as a first-in-first-out (FIFO) queue. Time Quantum: A fixed time quantum (also known as a time slice or time interval) is defined. This time quantum represents the maximum amount of CPU time that a process can have before it's preempted. Execution: The CPU scheduler selects the process at the front of the ready queue for execution. The selected proces