Posts

Showing posts from January, 2018

Write a C program to implement the ls | sort command. (Use unnamed Pipe)

#include<sys/types.h> #include<stdio.h> #include<stdlib.h> #include<unistd.h> int main() { int fd[2]; if(pipe(fd) == -1) { perror("ERROR creating a pipe\n"); exit(1); } if (!fork()) { close(1); // close the standard output file dup(fd[1]); // now fd[1] (the writing end of the pipe) is the standard output close(fd[0]); // I am the writer. So, I don’t need this fd execlp("ls", "ls", NULL); } else { close(0); // close the standard input file dup(fd[0]); close(fd[1]); execlp("sort", "sort", "-r", NULL); } return(0); }

Write C programs to implement ipc between two unrelated processes using named pipe

#include<stdio.h> #include<stdlib.h> #include<errno.h> #include<unistd.h> int main() { int pfds[2]; char buf[30]; if(pipe(pfds)==-1) { perror("pipe"); exit(1); } printf("writing to file descriptor #%d\n", pfds[1]); write(pfds[1],"test hello",10); printf("reading from file descriptor #%d\n ", pfds[0]); read(pfds[0],buf,10); printf("read\"%s\"\n" ,buf); }output: jethusai@jethusai-Lenovo-G560:~$ gedit pipe.c jethusai@jethusai-Lenovo-G560:~$ gcc pipe.c jethusai@jethusai-Lenovo-G560:~$ ./a.out writing to file descriptor #4 reading from file descriptor #3  read"test hello"

What is Storage management

Image
Storage management: The operating system abstracts from the physical properties of its storage devices to define a logical Storage unit, the file. The operating system maps files onto physical media and accesses these files via the storage devices. File-System Management Mass-Storage Management Caching I/O Systems File-System Management: Pile management is one of the most visible components of an operating system. Computers can store information on several different types of physical media. Magnetic disk, optical disk, and magnetic tape are the most common. Each of these media has its own characteristics and physical organization. Each medium is controlled by a device, such as a disk drive or tape drive, that also has its own unique characteristics. A file is a collection of related information defined by its creator. The operating system is responsible for the following activities in connection with file management: Creating and deleting files Creating and d

What is Memory management

Memory management Memory management function of operating helps in allocating the main memory space to the process and their data at the time of their execution. It must be mapped to absolute addresses and loaded into memory. To improve both the utilization of the CPU and the speed of the computer’s response to its users, general-purpose computers must keep several programs in memory, creating a need for memory management. The operating system is responsible for the following activities in connection with memory management: Keeping track of which parts of memory are currently being used and by whom Deciding which processes (or parts thereof) and data to move into and out of memory Allocating and deallocating memory space as needed.

what is the Process management

A program does nothing unless its instructions are executed by a CPU.A program in execution, as mentioned, is a process. A process is the unit of work in a system. Such a system consists of a collection of processes, some of which are operating-system processes (those that execute system code) and the rest of which are user processes (those that execute user cod) all the processes can potentially execute concurrently by multiplexing on a single cpu. The operating system is responsible for the following activities in connection with process management: Scheduling processes and threads on the CPUs Creating and deleting both user and system processes Suspending and resuming processes Providing mechanisms for process synchronization Providing mechanisms for process communication

Write a c program to implement Priority Scheduling algorithms non-preemptive

Algorithm: 1.        Start 2.       Declare the array size p[20],bt[20],pri[20], wt[20],tat[20],i, k, n, temp; float wtavg, tatavg,awt,tat; 3.       Read the number of processes to be inserted 4.       Read the Burst times of processes 5.       Sort the Burst times in ascending order and process with shortest burst time is first executed. for(i=0;i<n;i++) for(k=i+1;k<n;k++)                   if(pri[i] > pri[k])                   {                               temp=p[i];                                p[i]=p[k];                                p[k]=temp;                               temp=bt[i];                               bt[i]=bt[k];                               bt[k]=temp;                               temp=pri[i];                               pri[i]=pri[k];                               pri[k]=temp;                   } 6.       Waiting time for first process will be zero wtavg = wt[0] = 0; tatavg = tat[0] = bt[0]; 7.

Shortest Job First (SJF) scheduling

Image
Shortest Job First (SJF) scheduling In this algorithm there are three algorithms those are: ·          SJF   is a non-preemptive algorithm ·          Shortest Remaining Time First (SRTF) ·          Longest Remaining Time First (LRTF) SJF is a non-preemptive algorithm Shortest job first (SJF), is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJN is a non-preemptive algorithm. 1.       Shortest Job first has the advantage of having minimum average waiting time among all scheduling algorithms. 2.       It is a Greedy Algorithm. 3.       It may cause starvation if shorter processes keep coming. This problem can be solved using the concept of aging. 4.       It is practically infeasible as Operating System may not know burst time and therefore May not sort them. While it is not possible to predict execution time, several methods can be used to estimate the execution time for a job, such as a weighte

First come first served scheduling algorithm (FCFS)

Image
First come first served scheduling algorithm (FCFS) FCFS also termed as First-In-First-Out i.e. allocate the CPU in order in which the process arrive. When the CPU is free, it is allowed to process, which is occupying the front of the queue. Once this process goes into running state, its PCB is removed from the queue. This algorithm is non-preemptive. Advantage Suitable for batch system. It is simple to understand and code. Disadvantage Waiting time can be large if short request wait behind the long process. It is not suitable for time sharing system where it is important that each user should get the CPU for equal amount of time interval. Examples consider the following set of processes having their CPU-burst time. CPU burst time indicates that for how much time, the process needs the CPU. If the processes have arrived in order P0, P1, P2, P3 then the average waiting time for process will be obtained from Gantt chart.