본문 바로가기

개발자/Raspberry Pi

리눅스에서 프로세스 중단 kill 하는 방법

반응형



리눅스에서 부팅시 실행시킨 프로세스를 중지하는 방법입니다.

실행되는 프로세스를 정지할때 사용합니다.

 

PID를 확인한다. top 명령어를 통해서 PID를 확인하는데 맨 앞에 나오는 것이 PID.



pi@raspberrypi ~ $ top
top - 16:57:32 up 5 min,  2 users,  load average: 0.07, 0.19, 0.12
Tasks:  81 total,   1 running,  80 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  1.0 sy,  0.0 ni, 98.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:    380720 total,   159888 used,   220832 free,    14936 buffers
KiB Swap:   102396 total,        0 used,   102396 free,    74336 cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
 3433 pi        20   0  4692 2408 2012 R   1.6  0.6   0:00.22 top
 3035 mysql     20   0  309m  40m 9296 S   0.3 10.9   0:03.52 mysqld
    1 root      20   0  2152 1384 1280 S   0.0  0.4   0:01.92 init
    2 root      20   0     0    0    0 S   0.0  0.0   0:00.00 kthreadd
    3 root      20   0     0    0    0 S   0.0  0.0   0:00.21 ksoftirqd/0
    5 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kworker/0:0H
    7 root      20   0     0    0    0 S   0.0  0.0   0:00.64 rcu_preempt
    8 root      20   0     0    0    0 S   0.0  0.0   0:00.00 rcu_sched
    9 root      20   0     0    0    0 S   0.0  0.0   0:00.00 rcu_bh
   10 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 khelper
   11 root      20   0     0    0    0 S   0.0  0.0   0:00.01 kdevtmpfs
   12 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 netns
   13 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 perf
   14 root      20   0     0    0    0 S   0.0  0.0   0:00.00 khungtaskd
   15 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 writeback
   16 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 crypto
   17 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 bioset
   18 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kblockd
   19 root      20   0     0    0    0 S   0.0  0.0   0:01.14 kworker/0:1
   20 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 rpciod
   21 root      20   0     0    0    0 S   0.0  0.0   0:00.00 kswapd0
   22 root      20   0     0    0    0 S   0.0  0.0   0:00.00 fsnotify_mark
   23 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 nfsiod
   31 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kthrotld
   32 root       1 -19     0    0    0 S   0.0  0.0   0:00.25 VCHIQ-0
   33 root       1 -19     0    0    0 S   0.0  0.0   0:00.00 VCHIQr-0
   34 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 VCHIQs-0
   35 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 iscsi_eh
   36 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 dwc_otg
   37 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 DWC Notificatio
   38 root      20   0     0    0    0 S   0.0  0.0   0:00.12 kworker/u2:1
   39 root      20   0     0    0    0 S   0.0  0.0   0:00.00 VCHIQka-0
   40 root      10 -10     0    0    0 S   0.0  0.0   0:00.00 SMIO
   41 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 deferwq
   42 root      20   0     0    0    0 S   0.0  0.0   0:00.86 mmcqd/0
   43 root      20   0     0    0    0 S   0.0  0.0   0:00.00 kworker/u2:2
   44 root      20   0     0    0    0 S   0.0  0.0   0:00.01 kworker/0:2
   45 root      20   0     0    0    0 S   0.0  0.0   0:00.01 jbd2/mmcblk0p2-
   46 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 ext4-rsv-conver
  161 root      20   0  2928 2264 1696 S   0.0  0.6   0:00.61 udevd
  254 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 20204000.spi
  298 root      20   0  2924 2076 1492 S   0.0  0.5   0:00.02 udevd
  303 root      20   0  2924 1964 1388 S   0.0  0.5   0:00.01 udevd
 1664 root      20   0  1756 1232 1140 S   0.0  0.3   0:00.29 ifplugd
 1679 root      20   0  1756 1300 1208 S   0.0  0.3   0:00.48 ifplugd
 1685 root      20   0  1756 1220 1136 S   0.0  0.3   0:00.06 ifplugd



PID를 확인하는 다른 방법은 ps -ax 로 확인합니다.



pi@raspberrypi ~ $ ps -ax
warning: bad ps syntax, perhaps a bogus '-'?
See http://gitorious.org/procps/procps/blobs/master/Documentation/FAQ
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:01 init [2]
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:00 [ksoftirqd/0]
    5 ?        S<     0:00 [kworker/0:0H]

   45 ?        S      0:00 [jbd2/mmcblk0p2-]
   46 ?        S<     0:00 [ext4-rsv-conver]
  161 ?        Ss     0:00 udevd --daemon
  254 ?        S<     0:00 [20204000.spi]
  298 ?        S      0:00 udevd --daemon
  303 ?        S      0:00 udevd --daemon
 1664 ?        S      0:00 /usr/sbin/ifplugd -i eth0 -q -f -u0 -d10 -w -I
 1679 ?        S      0:00 /usr/sbin/ifplugd -i wlan0 -q -f -u0 -d10 -w -I
 1685 ?        S      0:00 /usr/sbin/ifplugd -i lo -q -f -u0 -d10 -w -I
 1688 ?        S      0:00 [RTW_CMD_THREAD]
 1698 ?        Ss     0:00 /sbin/wpa_supplicant -s -B -P /var/run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -C /var/run
 1774 ?        Ss     0:00 dhclient -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0
 1873 ?        Ss     0:00 dhclient -v -pf /run/dhclient.wlan0.pid -lf /var/lib/dhcp/dhclient.wlan0.leases wlan0
 2291 ?        Ss     0:00 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfi
 2294 ?        Sl     0:00 /usr/sbin/rsyslogd -c5
 2345 ?        Ss     0:00 /usr/sbin/apache2 -k start
 2384 ?        S      0:00 /usr/sbin/apache2 -k start


여기서 중지하고자 하는 PID 를 확인하고 $ sudo kill -9 PID 하면 프로세스가 종료됩니다.


pi@raspberrypi ~ $ sudo kill -9 2406

killed


이만....






반응형

더욱 좋은 정보를 제공하겠습니다.~ ^^