MultiTasking in UNIX

Unix is a versatile system environment. If you are familiar with the shell scripting....then you should be familiar with the usage of the operator called pipe... A pipe is represented by a vertical line '|' . It is used to join two or more shell scripts... One way looking at it is when you want the output of one command to be the input of other then you pipe those two commands... Here is an illustration of the multitasking. Since there is no intermediate file created when pipe operator is used, this means that the two programs at each end of the pipe have to be running together at the same time so the output of the first program can be used as input for the second as it is created. Similarly when you run a 'shell', usually called a 'terminal' or the 'command prompt', we are actually running a process. When we execute some command such as like a 'gedit filename'. The shell uses the facility called 'fork' to split itself into two process. The shell becomes the parent process and the command e 'gedit filename' becomes a child process. The child process uses another Unix facility called 'exec' to execute the command and exit. The parent process uses a 'wait' command until the child process completes its execution and it terminates. By this method the Unix ensures that shell, executes the commands you enter as though they were subroutines.
diagramatically it can be shown as ->

Some times the child process might produce lots of output that the output is written onto a file. This means that you will have to wait for a long time before the parent wakes up and you can run your next command. So if you don't wish to wait and want the child process to run in the background... then you just need to append and ampersand '&' at the end of your command line. In this situation the 'fork' command creates the child and parent process as before, but the parent does not execute the 'wait' system call, but it returns to the next shell prompt immediately. Thus the child runs in the background and the parent in the foreground as shown here


Post a Comment

^ Scroll to Top