Use C for high level language implementation 1. Write programs using the following system calls of UNIX operating system: fork, exec, getpid, exit, wait, close, stat, opendir, readdir. For each of the scheduling policies, compute and print the average waiting time and average turnaround time. Developing Application using Inter Process communication using shared memory, pipes or message queues.
|Published (Last):||23 October 2013|
|PDF File Size:||7.92 Mb|
|ePub File Size:||9.29 Mb|
|Price:||Free* [*Free Regsitration Required]|
Use C for high level language implementation Write programs using the following system calls of UNIX operating system: fork, exec, getpid, exit, wait, close, stat, opendir, readdir. For each of the scheduling policies, compute and print the average waiting time and average turnaround time. Developing Application using Inter Process communication using shared memory, pipes or message queues.
Each memory request consists of the process-id and the amount of storage space required in bytes. Allocated memory space is again maintained as a linked list of nodes with each node having the process-id, starting byte address and the ending byte address of the allocated space.
When a process finishes taken as input the appropriate node from the allocated list should be deleted and this free disk space should be added to the free space list. This results in deleting more than one node from the free space list and changing the start and end address in the appropriate node].
For allocation use first fit, worst fit and best fit. TOTAL: A system call is just what its name implies - a request for the operating system to do something on behalf of the user's program.
The system calls are functions used in the kernel itself. To the programmer, the system call appears as a normal C function call. However since a system call executes code in the kernel, there must be a mechanism to change the mode of a process from user mode to kernel mode. The C compiler uses a predefined library of functions the C library that have the names of the system calls.
The library functions typically invoke an instruction that changes the process execution mode to kernel mode and causes the kernel to start executing code for system calls. The instruction that causes the mode change is often referred to as an "operating system trap" which is a software generated interrupt.
The library routines execute in user mode, but the system call interface is a special case of an interrupt handler. The library functions pass the kernel a unique number per system call in a machine dependent way.
This is often used by routines that generate unique temporary file names. The contents of the child process are identical to the contents of the parent process. The prototype for the fork system call is: int fork. CS - Operating Systems Laboratory The new process inherits several characteristics of the old process. Among the characteristics inherited are: The environment.
All signal settings. The set user ID and set group ID status. The time left until an alarm clock signal. The current working directory and the root directory. The file creation mask as established with umask. The child process begins executing and the parent process continues executing at the return from the fork system call. This is difficult to understand at first because you only call fork once, yet it returns twice -- once per process.
To differentiate which process is which, fork returns zero in the child process and non-zero the child's process ID in the parent process. The UNIX system calls that transform a executable binary file into a process are the "exec" family of system calls.
The prototypes for these calls are:. You can control the execution of child processes by calling wait in the parent. If the child finishes before the parent gets around to calling wait , then when wait is called by the parent, it will return immediately with the child's process ID. It is possible to have more that one child process by simply calling fork more than once. The prototype for the exit system call is: void exit status int status; where status is an integer between 0 and Note: since wait returns the exit status multiplied by contained in the upper 8 bits , the status value is shifted right 8 bits divided by to obtain the correct value.
File Status stat ,fstat , lstat The i-node data structure holds all the information about a file except the file's name and its contents. Sometimes your programs need to use the information in the i-node structure to do some job. You can access this information with the stat , lstat and fstat system calls. The stream is positioned at the first entry in the directory.
The parameter count is ignored; at most one dirent structure is read. The directory stream descriptor dir is not available after this call. Include necessary header files for using systems calls. Make necessary declaration. Get the process identification number and parent process identification number using getpid and getppid system calls 4. Thus C program was written programs using the fork, exec, getpid, exit, wait, stat, opendir, readdir system calls of UNIX operating system.
Description open open lets you open a file for reading, writing, or reading and writing. The read system call does all input and the write system call does all output.
When used together, they provide all the tools necessary to do input and output sequentially. Result : Thus C program was written using open , read , write and close system calls. Lab Manual. Simulation of Unix Commands To write a C program to simulate basic Unix commands like ls,grep, cp,rm. In addition, programming language construct can also be used to avail the UNIX commands. Exercises : 1. Siumulation of ls command Algorithm : 1. Include necessary header files for manipulating directory.
Declare and initialize required objects. Read the directory name form the user 4. Open the directory using opendir system call and report error if the directory is not available 5.
Read the entry available in the directory 6. Display the directory entry ie. Repeat the step 6 and 7 until all the entries were read. Simulation of grep command. Algorithm : 1. Include necessary header files 2.
Make necessary declarations 3. Read the file name from the user and open the file in the read only mode. Read the pattern from the user. Read a line of string from the file and search the pattern in that line. If pattern is available, print the line. Repeat the step 4 to 6 till the end of the file. Simulation of cp command Algorithm: 1. Include required header file 2. Read the source and destination file names from the user. Using read system call, read the content of the file to the buffer.
Uing write system call, write the buffer content to the destination file. Close the opened files. Read the file name from the user. Using remove system call remove the file from the user. The problem of determining when processors should be assigned and to which processes is called processor scheduling or CPU scheduling.
When more than one process is runable, the operating system must decide which one first. The part of the operating system concerned with this decision is called the scheduler, and algorithm it uses is called the scheduling algorithm. Perhaps, First-Come-First-Served algorithm is the simplest scheduling algorithm is the simplest scheduling algorithm. Processes are dispatched according to their arrival time on the ready queue. Being a nonpreemptive discipline, once a process has a CPU, it runs to completion.
The FCFS scheduling is fair in the formal sense or human sense of fairness but it is unfair in the sense that long jobs make short jobs wait and unimportant jobs make important jobs wait. FCFS is more predictable than most of other schemes since it offers time.
FCFS scheme is not useful in scheduling interactive users because it cannot guarantee good response time. The code for FCFS scheduling is simple to write and understand. One of the major drawback of this scheme is that the average time is often quite long.
Shortest-Job-First SJF is a non-preemptive discipline in which waiting job or process with the smallest estimated run-time-to-completion is run next. The SJF scheduling is especially appropriate for batch jobs for which the run times are known in advance.
Since the SJF scheduling algorithm gives the minimum average time for a given set of processes, it is probably optimal. The SJF algorithm favors short jobs or processors at the expense of longer ones.
The obvious problem with SJF scheme is that it requires precise knowledge of how long a job or process will run, and this information is not usually available. The best SJF algorithm can do is to rely on user estimates of run times. In the production environment where the same jobs run regularly, it may be possible to.
CS2257 OS Lab Manual
Operating System Lab Manual - CS2257