Raspberry Pi_Eng_19.1.2 Killing Process


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


19.1.2  Killing Process

 

If the current process is no longer needed, or if there is a problem with the progress of the process, you can terminate the processing of a specified particular process.

 

19.1.2.1    "kill" Command Terminate Process Using PID

 

"kill" command tells the system to terminate the process running on the system.

 

[Command Format]

kill  [ options ]  <signal>  <PID>

 

[Command Overview]

    This terminates the currently running process.

    User privilege           -- Normal user.

 

[Detail Description]

"kill" command does not handle the target process directly, but rather "kill" command only send a signal to the process to perform a specific action and the process that received the signal have the responsibility to actually perform the action corresponding to the signal. Therefore, if the process receives a signal and does nothing, it would be no effect to send the signal.

 

There are 64 kinds of signals available in Linux. The main signals are as follows.

 

signal no.

signal code

description

1

SIGHUP

Hang-up. Terminate current connection. It is usually used for re-initialization.

2

SIGINT

Initialize

3

SIGQUIT

Shutdown Normally

4

SIGILL

 

5

SIGTRAP

 

6

SIGABRT

Abort

7

SIGBUS

 

8

SIGFPE

 

9

SIGKILL

Terminate application

10

SIGUSR1

 

11

SIGSEGV

 

12

SIGUSR2

 

13

SIGPIPE

 

14

SIGALRM

alarm

15

SIGTERM

Terminate. default action of "kill" command

16

SIGSTKFLT

 

17

SIGCHLD

 

18

SIGCONT

continue

19

SIGSTOP

Stop

20

SIGTSTP

 

~중략

 

 

34 ~ 49

SIGRTMIN ~

SIGRTMIN+15

 

50 ~ 64

SIGRTMAX-14 ~

SIGRTMAX

 

 

When you specify signal in the "kill" command, you can specify the number, or specify all or part of the code. In other words, if "SIGKILL", you can use "-9", "-SIGKILL", "-KILL", and so on.

 

If you do not specify a signal, use "SIGTERM" (no "15") as default.

 

The PID is a process id assigned to a specific process currently being executed. When you look up the process list, there is usually a PID column, which displays the PID assigned to the process.

 

You can use a negative PID instead of specifying a normal PID for special processing. A negative PID is used to select all process groups. For the process group, see the PGID column of "ps" command. If the PID is "-1", it is used to refer to all process except "kill" process itself and init.

 

[Main option]

-<signal>

-s <signal>

--signal <signal>

Specify the signal to be sent. The signal can be specified by using name

or number. The behavior of signals is explained in signal(7) manual page.

-l, --list [signal]

List signal names. This option has optional argument, which will convert

signal number to signal name, or other way round.

-L, --table

List signal names in a nice table.

 

The following is the result to display processes only related to the <Motion> program.

 

pi@raspberrypi ~ $ ps -ef | grep motion

motion    6835     1  1 19:07 ?        00:01:19 /usr/bin/motion

pi        7053  6586  0 20:16 pts/0    00:00:00 grep --color=auto motion

 

We now want to terminate the above PID "6836" <Motion> program process. Run the "kill" command as follows and run the same command again to see the results. You can then see that the process is no longer visible.

 

pi@raspberrypi ~ $ sudo kill 6835

 

pi@raspberrypi ~ $ ps -ef | grep motion

pi        7075  6586  0 20:27 pts/0    00:00:00 grep --color=auto motion


 

19.1.2.2    "killall" Command Terminate Process with Name

 

"killall" command is the command to send a signal selectively to only the process that processes the specific command among process running in the system.

 

[Command Format]

killall  [ options ]  <signal>  <name>

 

[Command Overview]

    This select only processes that process specific commands in the system and terminate them.

    User privilege           -- Normal user.

 

[Detail Description]

    "killall" sends signal to all processes executing the specified command. If no signal is specified, SIGTERM is used by default.

 

[Main option]

-e, --exact

Require an exact match for very long names. If a command name is longer than 15 characters, the full name may be unavailable (i.e. it is swapped out). In this case, killall will kill everything that matches within the first 15 characters. With -e, such entries are skipped. killall prints a

message for each skipped entry if -v is specified in addition to -e,

-i, --interactive

Interactively ask for confirmation before killing.

-l, --list

List all known signal names.

-s, --signal

 

Send this signal instead of SIGTERM.

 

-u, --user

Kill only processes the specified user owns. Command names are optional.

 

[Used Example]

The following shows only processes related to the <Motion> program.

 

pi@raspberrypi ~ $ ps -ef | grep motion

motion    6835     1  1 19:07 ?        00:01:19 /usr/bin/motion

pi        7053  6586  0 20:16 pts/0    00:00:00 grep --color=auto motion

 

The following shows the result that we execute the "killall" command for the process executing the <Motion> program command and again check the status of the processes executing the <Motion> program command. Notice that the previously running process has disappeared.

 

pi@raspberrypi ~ $ sudo killall motion

 

pi@raspberrypi ~ $ ps -ef | grep motion

pi        7187  6586  0 20:41 pts/0    00:00:00 grep --color=auto motion


 

19.1.2.3    Terminating Process Using Desktop Window

 

When accessing Raspberry Pi's Desktop window, [Task Manager] can be used to monitor the system through the window screen.

 

When you run Window Application Menu Menu àAccessories àTask Manager, the [Task Manager] screen appears as shown below.

 

Here, the user can select the required task to interrupt or resume the operation as shown below, and can terminate the operation if necessary. It provides the ability to manage tasks without entering commands.


Figure 19‑3 Terminating process in Desktop window

 

Here is what you can do on this screen.

    Stop

    continue

    Terminate

    Kill

    Adjust priority