샤인의 IT (막 적는) 메모장

[Linux] Process & Archive 본문

Cloud Infra/Linux

[Linux] Process & Archive

신샤인 2022. 1. 15. 14:45
반응형

 

 

Process

#top - 동작중인 프로세스 및 리소스 확인
[root@localhost yum.repos.d]# top

top - 14:59:40 up  3:03,  1 user,  load average: 0.00, 0.01, 0.05
#프로세스 정보
Tasks: 120 total,   1 running, 119 sleeping,   0 stopped,   0 zombie
#CPU 정보
%Cpu(s):  0.0 us,  0.2 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st
#메모리 정보
KiB Mem :   498508 total,   111632 free,   119004 used,   267872 buff/cache
KiB Swap:  1048572 total,  1047028 free,     1544 used.   362948 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  868 root      20   0  437356   1828   1332 S   0.3  0.4   0:05.90 VBoxService
 1943 vagrant   20   0  155044   2592   1160 S   0.3  0.5   0:07.11 sshd
 2659 root      20   0  162124   2244   1536 R   0.3  0.5   0:00.02 top
    1 root      20   0  128232   6496   3828 S   0.0  1.3   0:01.73 systemd
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.01 kthreadd
    4 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H
    5 root      20   0       0      0      0 S   0.0  0.0   0:00.08 kworker/u4:0
    6 root      20   0       0      0      0 S   0.0  0.0   0:00.77 ksoftirqd/0
    7 root      rt   0       0      0      0 S   0.0  0.0   0:00.05 migration/0
    8 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S   0.0  0.0   0:02.01 rcu_sched
   10 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 lru-add-drain
   11 root      rt   0       0      0      0 S   0.0  0.0   0:00.38 watchdog/0
   12 root      rt   0       0      0      0 S   0.0  0.0   0:00.57 watchdog/1
   13 root      rt   0       0      0      0 S   0.0  0.0   0:00.10 migration/1
   14 root      20   0       0      0      0 S   0.0  0.0   0:02.99 ksoftirqd/1
   16 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/1:0H
   19 root      20   0       0      0      0 S   0.0  0.0   0:00.01 kdevtmpfs
   20 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 netns
   21 root      20   0       0      0      0 S   0.0  0.0   0:00.00 khungtaskd
   22 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 writeback
   23 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kintegrityd
...

#ps - 프로세스 확인
[root@localhost yum.repos.d]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  1.3 128232  6496 ?        Ss   11:55   0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root         2  0.0  0.0      0     0 ?        S    11:55   0:00 [kthreadd]
root         4  0.0  0.0      0     0 ?        S<   11:55   0:00 [kworker/0:0H]
root         5  0.0  0.0      0     0 ?        S    11:55   0:00 [kworker/u4:0]
root         6  0.0  0.0      0     0 ?        S    11:55   0:00 [ksoftirqd/0]
...

[root@localhost yum.repos.d]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 11:55 ?        00:00:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root         2     0  0 11:55 ?        00:00:00 [kthreadd]

#kill - 프로세스 종료
[root@localhost yum.repos.d]# ps -ef | grep httpd
root      2631     1  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2632  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2633  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2634  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2635  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2636  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root      2681  1972  0 15:03 pts/0    00:00:00 grep --color=auto httpd
[root@localhost yum.repos.d]# kill -9 2632
[root@localhost yum.repos.d]# ps -ef | grep httpd
root      2631     1  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2633  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2634  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2635  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2636  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2682  2631  0 15:03 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root      2684  1972  0 15:03 pts/0    00:00:00 grep --color=auto httpd

# 해당 ps 출력 문자열을 슬라이싱 해서 명령어 수행
[root@localhost yum.repos.d]# ps -ef | grep httpd | grep -v 'grep'
root      2631     1  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2633  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2634  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2635  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2636  2631  0 14:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    2682  2631  0 15:03 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
[root@localhost yum.repos.d]# ps -ef | grep httpd | grep -v 'grep' | awk ' {print $2}'
2631
2633
2634
2635
2636
2682

#xargs로 명령어 수행! ls는 테스트
[root@localhost yum.repos.d]# ps -ef | grep httpd | grep -v 'grep' | awk ' {print $2}' | xargs ls
ls: cannot access 2631: No such file or directory
ls: cannot access 2633: No such file or directory
ls: cannot access 2634: No such file or directory
ls: cannot access 2635: No such file or directory
ls: cannot access 2636: No such file or directory
ls: cannot access 2682: No such file or directory



[root@localhost yum.repos.d]# ps -ef | grep httpd | grep -v 'grep' | awk ' {print $2}' | xargs kill -9

[root@localhost yum.repos.d]# ps -ef | grep httpd | grep -v 'grep' # 프로세스 제거하고 없음

 

 

Archive

#tar -czvf (c)create (z)compress v(visual) f(file)


#tar 압축
[root@localhost log]# tar -czvf yum_log-20220115.tar yum.log-20220114
yum.log-20220114
[root@localhost log]# ls
anaconda           btmp-20220114  dmesg.old           maillog            samba             tallylog             vboxadd-setup.log.2  yum_log-20220115.tar
audit              chrony         grubby              maillog-20220114   secure            tuned                vboxadd-setup.log.3
boot.log           cron           grubby_prune_debug  messages           secure-20220114   vboxadd-install.log  wtmp
boot.log-20220114  cron-20220114  httpd               messages-20220114  spooler           vboxadd-setup.log    yum.log
btmp               dmesg          lastlog             rhsm               spooler-20220114  vboxadd-setup.log.1  yum.log-20220114
[root@localhost log]# file yum_log-20220115.tar.gz
yum_log-20220115.tar.gz: gzip compressed data, from Unix, last modified: Fri Jan 14 15:10:05 2022
[root@localhost log]# mkdir yum_log
[root@localhost log]# mv yum_log-20220115.tar.gz yum_log
[root@localhost log]# cd yum_log/
[root@localhost yum_log]# ls -alh
total 8.0K
drwxr-xr-x.  2 root root   37 Jan 14 15:10 .
drwxr-xr-x. 10 root root 4.0K Jan 14 15:10 ..
-rw-r--r--.  1 root root 2.5K Jan 14 15:10 yum_log-20220115.tar.gz

#tar 압축 풀기
[root@localhost yum_log]# tar -xzvf yum_log-20220115.tar.gz
yum.log-20220114
[root@localhost yum_log]# ls
yum.log-20220114  yum_log-20220115.tar.gz
[root@localhost yum_log]# ls -alh
total 20K
drwxr-xr-x.  2 root root   61 Jan 14 15:10 .
drwxr-xr-x. 10 root root 4.0K Jan 14 15:10 ..
-rw-------.  1 root root  12K Jan 14 12:09 yum.log-20220114
-rw-r--r--.  1 root root 2.5K Jan 14 15:10 yum_log-20220115.tar.gz

#zip / unzip
[root@localhost log]# zip -r httpd.zip httpd/
  adding: httpd/ (stored 0%)
  adding: httpd/error_log (deflated 68%)
  adding: httpd/access_log (stored 0%)
  adding: httpd/.zip (stored 0%)
[root@localhost log]# ls -alh

[root@localhost yum_log]# unzip httpd.zip
Archive:  httpd.zip
   creating: httpd/
  inflating: httpd/error_log
 extracting: httpd/access_log
 extracting: httpd/.zip
[root@localhost yum_log]# ls -alh
total 8.0K
drwxr-xr-x.  3 root root   36 Jan 14 15:17 .
drwxr-xr-x. 10 root root 4.0K Jan 14 15:17 ..
drwx------.  2 root root   53 Jan 14 15:16 httpd
-rw-r--r--.  1 root root 1.2K Jan 14 15:16 httpd.zip
반응형

'Cloud Infra > Linux' 카테고리의 다른 글

[Linux] Package & Service  (0) 2022.01.15
[Linux] User Group & Permission  (0) 2022.01.15
[Linux] File Type & IO Redirection  (0) 2022.01.15
[Linux] 기본 명령어 정리  (0) 2022.01.15
[Linux] Rocky Linux 설치  (0) 2021.05.15
Comments