Page 197 - DCAP602_NETWORK_OPERATING_SYSTEMS_I
P. 197

Unit 10: File System




          There are several commands that can be used to control processes. They are:           notes
          1.   ps – list the processes running on the system

          2.   kill – send a signal to one or more processes (usually to “kill” a process)
          3.   jobs – an alternate way of listing your own processes
          4.   bg – put a process in the background
          5.   fg – put a process in the forground
          While it may seem that this subject is rather obscure, it can be very practical for the average user
          who mostly works with the graphical user interface. You might not know this, but most if not
          all of the graphical programs can be launched from the command line. Here’s an example: there
          is a small program supplied with the X Windows system called xload which displays a graph
          representing system load. You can excute this program by typing the following:

          $ xload
          Notice that the small xload window appears and begins to display the system load graph. Notice
          also that your prompt did not reappear after the program launched. The shell is waiting for
          the program to finish before control returns to you. If you close the xload window, the xload
          program terminates and the prompt returns.
          Now in order to make life a little easier, we are going to launch the xload program again, but
          this time we will put it in the background so that the prompt will return. To do this we execute
          xload like this:

          $ xload &
          [1] 1223
          $
          In this case, the prompt returned because the process was put in the background.

          Now imagine that you forgot to use the “&” symbol to put the program into the background.
          There is still hope. You can type control-z and the process will be suspended. The process still
          exists but is idling. To resume the process in the background type the bg command (short for
          background). Here is an example:

          $ xload
          [2]+ Stopped xload
          $ bg
          [2]+ xload &
          Now that we have a process in the background, it would be helpful to display a list of the processes
          we have launched. To do this, we can use either the jobs command or the more powerful ps
          command.
          $ jobs
          [1]+ Running xload &
          $ ps
          PID TTY TIME CMD

          1211 pts/4 00:00:00 bash
          1246 pts/4 00:00:00 xload
          1247 pts/4 00:00:00 ps
          $


                                           LoveLy professionaL university                                   191
   192   193   194   195   196   197   198   199   200   201   202