DecordRay

[Linux] 용어 정리(nohup, 덤프, 터미널, 콘솔) 본문

공부/리눅스

[Linux] 용어 정리(nohup, 덤프, 터미널, 콘솔)

DecordRay 2023. 4. 26. 17:40
728x90
반응형

nohup

nohup은 프로세스를 실행한 터미널의 세션 연결이 끊기더라도 프로세스를 계속해서 동작시키는 명령어

기본적으로 터미널에서 세션의 logout이 발생하면, 해당 터미널에서 실행된 프로세스들에게 HUP 신호를 전달하여 프로세스들을 종료시킨다.

nohup은 프로세스들을 마치 데몬인 것처럼 동작시켜 이러한 HUP 시그널을 무시하도록 하는 명령어가 된다.

 

이를 요약하자면 

nohup 사용 안할 시(기존)

세션 logout -> 실행 프로세스들에게 HUP 신호 전달 -> 실행되고 있던 프로세스들 종료

 

nohup사용 시

세션 logout -> 실행 프로세스들에게 HUP 신호 전달 -> nohup이 HUP 시그널 무시하도록 함 -> 실행되고 있던 프로세스들 계속 수행

 

* nohup을 실행할 대상이 스크립트인 경우, 스크립트의 권한은 755 이상이어야 한다.

  • process name에는 실행할 프로그램 또는 스크립트 이름을 넣어준다. 
    • 실행할 대상이 스크립트인 경우, 스크립트의 권한은 755 이상이어야 한다고 함.
  • 예시 : 
    • nohup ./start.sh &
    • nohup python3 device-agent.py &

 

일반적인 리눅스 프로세스는 SSH 세션(로그아웃될 경우)이 종료될 경우 백그라운드 여부와 관계 없이 종료된다.

ubuntu@ip-10-0-0-21:~/tunneling-poc$ python3 device-agent.py &
[1] 9780
ubuntu@ip-10-0-0-21:~/tunneling-poc$ ps -aux | grep python3
root       751  0.0  2.5 170832 12308 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root       801  0.0  3.1 187680 15200 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
ubuntu    9781  2.5  3.8 290976 18504 pts/0    Sl   10:56   0:00 python3 device-agent.py
ubuntu    9789  0.0  0.2  14860  1112 pts/0    S+   10:56   0:00 grep --color=auto python3
ubuntu@ip-10-0-0-21:~/tunneling-poc$ exit
logout
Connection to 0.0.0.0 closed.
[~] ssh ubuntu@0.0.0.0

ubuntu@ip-10-0-0-21:~$ ps -aux | grep python3
root       751  0.0  2.5 170832 12308 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root       801  0.0  3.1 187680 15200 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
ubuntu    9875  0.0  0.2  14860  1080 pts/1    S+   10:56   0:00 grep --color=auto python3

 

nohup을 사용할 경우 ssh 세션이 종료되더라도 삭제되지 않도록할 수 있다.

  • 백그라운드로 실행한 nohup 프로세스의 output은 nohup.out으로 리다이렉션된다.
ubuntu@ip-10-0-0-21:~/tunneling-poc$ nohup python3 device-agent.py &
[1] 9882
ubuntu@ip-10-0-0-21:~/tunneling-poc$ nohup: ignoring input and appending output to 'nohup.out'

ubuntu@ip-10-0-0-21:~/tunneling-poc$ ps -aux | grep python3
root       751  0.0  2.5 170832 12308 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root       801  0.0  3.1 187680 15200 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
ubuntu    9883  1.4  3.7 290980 18416 pts/1    Sl   10:57   0:00 python3 device-agent.py
ubuntu    9891  0.0  0.2  14860  1044 pts/1    S+   10:58   0:00 grep --color=auto python3
ubuntu@ip-10-0-0-21:~/tunneling-poc$ exit
logout
Connection to 0.0.0.0 closed.
[~] ssh ubuntu@0.0.0.0
ubuntu@ip-10-0-0-21:~$ ps -aux | grep python3
root       751  0.0  2.5 170832 12308 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root       801  0.0  3.1 187680 15200 ?        Ssl  10:43   0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
ubuntu    9883  0.8  3.7 290980 18416 ?        Sl   10:57   0:00 python3 device-agent.py
ubuntu    9977  0.0  0.2  14860  1112 pts/0    S+   10:58   0:00 grep --color=auto python3
ubuntu@ip-10-0-0-21:~$ cd tunneling-poc
ubuntu@ip-10-0-0-21:~/tunneling-poc$ cat nohup.out
2021-02-15 10:52:46,763 - MqttCore initialized
2021-02-15 10:52:46,763 - Client id: iot_tunnel_ingnoh
2021-02-15 10:52:46,763 - Protocol version: MQTTv3.1.1
2021-02-15 10:52:46,763 - Authentication type: TLSv1.2 certificate based Mutual Auth.
2021-02-15 10:52:46,763 - Configuring endpoint...
2021-02-15 10:52:46,763 - Configuring alpn protocols...
2021-02-15 10:52:46,763 - Configuring certificates...
2021-02-15 10:52:46,764 - Performing sync connect...
2021-02-15 10:52:46,764 - Performing async connect...
2021-02-15 10:52:46,764 - Keep-alive: 600.000000 sec
2021-02-15 10:52:46,838 - Performing sync subscribe...
2021-02-15 10:52:56,880 - Performing sync subscribe...
2021-02-15 10:53:06,926 - Performing sync subscribe...

 

nohup으로 실행된 프로세스를 종료시키려면 다음의 명령어를 사용한다.

  • ps -aux | grep [Process_NAME]
  • kill -9 [PID]

Core dump(코어 덤프)

UNIX 계열에서 프로그램이 비정상적으로 종료되는 경우에 프로그램이 종료될 당시의 메모리 상태를 기록하여 생성된 파일

이 코어 덤프는 해당 프로그램에 어떤 문제가 있었는지 디버깅 하는 용도로 사용된다.

 

코어 덤프(core dump)는 메모리 덤프(memory dump), 시스템 덤프(system dump)라고도 불린다.(전부 같은말) 

 

즉, Core dump는 

프로그램이 비정상적으로 종료된 경우 종료될 당시의 메모리 상태를 가지고 어떤 문제가 있었는지 디버깅 하는 용도로 사용된다.


Terminal(터미널) vs Console(콘솔)

Terminal은 서버의 로컬이나 원격으로 접속할 수 있는 콘솔을 구현한 소프트웨어로 크게 GUI와 shell로 나눌 수 있다.

대부분 terminal을 열면 shell이 실행된다.

 

  • GUI(graphical user interface) - 사용자가 편리하게 사용할 수 있도록 그래픽으로 이루어 져있으며 클릭을 통해 조작이 가능하다. 우리가 흔히 쓰는 모든 프로그램이 GUI로 이루어져있다. 대표적인 예로 window와 mac이 있다.
  • Shell - shell은 텍스트 기반의 터미널이며 대표적인 예로 linux가 있다.

 

위 설명을 조금 풀어보면

예를들어 putty(=터미널)를 키면 shell이 나오고 이를 통해 커널에 명령을 전달 할 수 있다.

 

즉 구조적으로 설명하자면 위 그림처럼 User(=사용자)는 Shell을 통해 명령어를 입력하고 해당 명령어를 커널에 전달하고, 다시 커널은 해당 명령어를 수행한 결과를 Shell을 통해 User에게 전달해주는 역할을 수행한다.

 

여기서 터미널과 콘솔이 헷갈릴텐데 가장 큰 역할 차이는 원격제어 환경을 제공하느냐 안하느냐이다.

 

Terminal(터미널) - 원격제어 환경 제공 o

  • Ex) putty

Console(콘솔) - 원격제어 환경 제공 x

  • Ex) 명령 프롬프트(cmd)

 

728x90
반응형

'공부 > 리눅스' 카테고리의 다른 글

[Linux] 리눅스 기본 명령어  (0) 2023.04.27
Comments