Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Operating Systems CSCI03I04 Lab 2

Commands in UNIX operating system


For opening the black screen which is named as terminal in UNIX operating system, There are two ways by: typing shortcut ctrl-alt-t searching from dash for terminal

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

^z suspend currently running job;

kill currently running program and allow emergency kill of currently running program ^\ clean-up before exiting with no chance of cleanup

Command #1: Man PWD


It shows the details of each command in terms of name, abbreviation, description, author, copyright, parameters and when exiting from the page press q.

Command #2: PWD print currently working directory


It shows the current directory in the terminal, as u see in the terminal home/ahmed

Command #3:ls list files and directory


It lists all the available files and folders in the directory.

Command #4: mkdir Make directory


It creates new folder. In Ubuntu operating system directory means folder.

Command#5: cd change directory


In order to change the place of the current directory type cd and then the name of the directory that you want to go for.

Command #6: touch filename


In order to make a file in within the current directory, then you should type touch and filename

Command #7catConcatenate and display text files.


It shows the content of file in the directory by typing Cat and name of the file(s).

Another way of displaying content in one file by typing cat + filename

Command #8: head -N filename


It shows the first number of lines in a file, by specifying number of line head -N name of file head -2 ex1

Command #9: tail -N filename


It shows the last number of lines in a file, by specifying last number of lines in a file

Command #10 WC filename


wc -l : Prints the number of lines in a file. wc -w : prints the number of words in a file. wc -c : Displays the count of bytes in a file. wc -m : prints the count of characters from a file. wc -L : prints only the length of the longest line in a file.

10: number of lines 11: number of words 22: file size

Command #11:Sort filenamesort lines in file


Ascending order for numbers and alphabets

Command#12: date
It displays current date and time

Command #13:od filename


It displays content of a file in terms of bytes

Command #14 mv filename


Move or rename filename

mv source destination

Command #15rm file name


It removes files from directories

Command #16rmdir file name or rm rf


Removes files directories, by typing rmdir and name of the folder

command #17cp copy files and directories.


Cp sourcedestination It copies contents of a file in another file and directors

Command #18:Grep 'word' file name

Itprints lines matching a pattern

Command #19 echo word or calculations $ [numbers and operations]


It print argument sent as for calculations or displaying echo word word echo $[2+1+4] 7

Command #20clear is used for clearing all commands written before from the screen

Process state in windows

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.

Figure 1: Process state in Windows operating systems

Process state in Unix

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.

Figure 3: Process creationusing fork() system call

Figure 4 Process state in UNIX operating system

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.

Running: One process is executing in the CPU.

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.

You might also like