Operating Systems CSCI03I04 Lab 2
Operating Systems CSCI03I04 Lab 2
UNIX commands man Documentation for commands. cat Concatenate and display text files. cd Change working directory. clear Clear the screen. Copy files and directories. cp date Display the current date and time. diff mkdir Make directories. more Page through a text file. mv od pwd rm Move (rename) files and directories. Display the bytes in a file. Print current working directory. Remove files.
Show differences between two text files. rmdir Remove directories. echo Print arguments. sort Sort lines. grep Print lines matching a pattern. head Display the first few lines of a file. ls List files and directories. tail uniq wc Display the last few lines of a file. Remove adjacent duplicate lines. Count lines, words, and characters in a file.
Self-learning ^h, backspace ^d ^q ^c erase previously typed character ^u erase entire line of input so far typed for programs reading from
end-of-input for programs reading from end-of-input ^s terminal terminal continue writing to terminal
kill currently running program and allow emergency kill of currently running program ^\ clean-up before exiting with no chance of cleanup
Command#12: date
It displays current date and time
mv source destination
Command #20clear is used for clearing all commands written before from the screen
Each process has five states: indeed, the operation of a multiprogramming system can be described by a state transition diagram on the process states. The states of a process include: New:Anew process being created, but not yet included in the pool of executable processes. Ready: Processes that are waiting in a queue waiting to be executed when interrupted. Running:Process that is currently being executed by the CPU. Waiting:Process that cannot execute until some event occurs, such as completion of the currently running processor or byreceiving a specific signal or event. 5. Terminated: Terminated-a process that is about to be removed from the pool of executable processes, a process has finished execution and is no longer assigned for any execution, and its remaining resources and attributes are to be disassembled and returned to the operating systems.
1. 2. 3. 4.
Fork
o A process is created by another process executing fork() function. o The created process is named as child process which is created by the parent process the caller. o Each process has its own process identifier PID. o When executing there are two possible ways: The parent process executing concurrently with its children. Figure 2: Process forking Parent process waitsfor its children processes to terminate. o Child process gets a copy of process image of parent: both child and parent share the same code following fork() and same data, or child has new program loaded in it. o Child and parent processes share the same address space of the same program, or each one has its own address space in case of loading in different program. o After a new child process is created, both processes will execute the next instruction following the fork() system call. o fork() returns a negative value, the creation of a child process was unsuccessful. o fork() returns a zero to the newly created child process. o fork() returns a PID of child to the parent process. The parent and child processes have unique IDs.
Init: Initializing a process isn't instantaneous. It takes timeto occupy space in the process table and
has resources allocated to it, but not yet ready to run.
Ready: Processes are transferred from initialization state to ready state. Processes can only be
created ready to run, as fork() creates an almost exact duplicate of the calling process, and that process must have been runnable in order to call the fork function in the first place. A new process is added at the end of the scheduler's queue with the conditional priority.
Runnable:Process is ready to run,it has instructions to be executed, but isn't actually running
because some other process is on the CPU. Runnable processes are waiting in queues; it keeps a separate queue for each possible priority level. When it is time to select a new process for execution, the scheduler finds the highest priority non-empty queue, and selects the first process in queue to be executed.
sched. :When the scheduler selects a new process for execution, that process is loaded and allowed
to run. The scheduler requests a timer interrupt with a very short delay, so that it can take over again and give another process a turn.
Time: Just before letting a process run on the CPU, the scheduler requests a timer interrupt for a
short distance into the future. When that interrupt happens, the scheduler takes over again. The process that was executing on the CPU is put into suspended animation, its volatile state is saved somewhere safe, and then is put back at the end of the scheduler's queue for the appropriate priority level.
Request: A running process will not use up all of its turn on the CPU.It may be suspended for any
reason by using sleep () or wait () functions, but it is not put back on the end of one of the scheduler's queues. It is kept in a pool of inactive processes.
Waiting: The state of a process which is not terminated, but for some reason cannot run just yet, so
cannot be put on any of the scheduler's queues. A process may be waiting for I/O, a hard page fault, a specified sleep time.Most systems distinguish between a large numbers of different "waiting" states. A process that is waiting for a problem to be recovered as a hard page fault is likely to wake up again after specific time.
Completed: When any event or action happens, the waiting process becomes able to run again. It
can't just take over the CPU immediately, because some other process will be running. But it is added to the end of the scheduler's queue with the specific priority. If a process with higher priority than the one currently running becomes runnable again because of some event, most systems will immediately simulate a timer interrupt, so the running process is suspended, and the newly runnable high-priority can start to run immediately.
Exit: The currently running process can terminate is by executing a call to the system function
exit(). The program jumps to a type of interrupt handling function that then calls the exit() function.
Exiting: Process can't completely terminate because it wants to every process that creates another
process (using fork) has to be notified when that process terminates, and find out whether it completed its task successfully or not. A process that has executed the exit() function will never run again, and has most of its resources released back to the system, but is not completely destroyed until its parent has notified of the termination notification message. Processes that have exitted but whose parents have not notified, are in the "exitting" state are called :Zombie Processes. If a program that executes fork() but does not execute wait() correctly, system will cluttered up with zombie processes. Not many resources are occupied, but do fill up a slot in the process table.
Deleted: Once a process' termination signal has been sent, the process is completely removed. All
its pages of memory and all other resources are returned to the system, and its slot in the process table is empty. Eventually even its PID number may be re-used.
Unix operating systems contains five different waiting states: - Page Wait:The process has a hard page fault and is waiting for a virtual page to be paged back
into physical memory. Page file reads are sometimes given a higher priority than normal disc file reads, and on more expensive systems, the virtual memory page file has a whole fast disc drive to itself, so page waits are usually the shortest waits of all. Disc Wait: The process is waiting for a normal disc operation to complete. This usually takes a few milli-seconds. Sleeping: The program has executed the sleep() ,usleep(), or similar functions, requesting a few seconds of delay. Idle Wait:The process is waiting for something to happen for specific period of timeusually couple of seconds. All input from an interactive user causes an idle wait. Furthermore,sleep() or usleep() functions request more than just a couple of seconds' delay. Stopped: It happens when user types control-Z, which means the process is just stopped not being terminated or killed and could woke up again after being in sleeping state for specific period of time by using fg command.