Page 198 - DCAP602_NETWORK_OPERATING_SYSTEMS_I
P. 198

Network Operating Systems-I




                    notes          Suppose that you have a program that becomes unresponsive, how do you get rid of it? You use
                                   the kill command, of course. Let’s try this out on xload. First you need to identify the process
                                   you want to kill. You can use either jobs or ps to do this. If you use jobs you will get back a job
                                   number. With ps, you are given a process id (PID). We will do it both ways:
                                   $ xload &
                                   [1] 1292
                                   $ jobs
                                   [1]+ Running xload &
                                   $ kill %1
                                   $ xload &
                                   [2] 1293
                                   [1] Terminated xload
                                   $ ps

                                   PID TTY TIME CMD
                                   1280 pts/5 00:00:00 bash
                                   1293 pts/5 00:00:00 xload
                                   1294 pts/5 00:00:00 ps
                                   $ kill 1293
                                   [2]+ Terminated xload
                                   $
                                   While the kill command is used to “kill” processes, its real purpose is to send signals to processes.
                                   Most of the time the signal is intended to tell the process to go away, but there is more to it than
                                   that. Programs (if they are properly written) listen for signals from the operating system and
                                   respond to them, most often to allow some graceful method of terminating.

                                          Example:

                                   A text editor might listen for any signal that indicates that the user is logging off or that the
                                   computer is shutting down. When it receives this signal, it saves the work in progress before it
                                   exits. The kill command can send a variety of signals to processes. Typing:
                                   kill -l
                                   will give you a list of the signals it supports. Most are rather obscure, but several are useful to
                                   know:

                                    signal #   name                           Description
                                   1         SIGHUP   Hang up signal. Programs can listen for this signal and act (or not act) upon it.
                                   15        SIGTERM  Termination signal. This signal is given to processes to terminate them. Again,
                                                      programs can process this signal and act upon it. You can also issue this signal
                                                      directly by typing control-c in the terminal window where the program is
                                                      running. This is the default signal sent by the kill command if no signal is
                                                      specified.
                                   9         SIGKILL  Kill signal. This signal causes the immediate termination of the process by the
                                                      Linux kernel. Programs cannot listen for this signal.









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