본문 바로가기

리눅스/명령어

[백그라운드 프로세스 - nohup]

nohup


설명

백그라운드 프로세스로 작업할 떄 사용하는 명령어.

nohup은 실행한 명령을 자동으로 백그라운드로 보내지 않고 , 사용자가 명령행 뒤에 '&'를 붙여야 한다.

HUP(Hangup) 시그널을 무시하고 프로그램을 지속적으로 실행할 떄 사용.


명령어

nohup [명령] &


실습

1) nohup

[root@localhost /]# echo hello

hello

[root@localhost /]# nohup echo hello

nohup: ignoring input and appending output to `nohup.out'


nohup 명령어로 echo hello 명령을 수행한다.

수행한 명령이 현재위치 nohup.out 파일에 로그로 기록된다.


[root@localhost /]# ls -ld nohup.out 
-rw-------. 1 root root 6 2017-11-05 20:34 nohup.out
[root@localhost /]# cat nohup.out 
hello

nohup.out 로그 확인시 위에서 실행한 명령이 저장되있는 것을 확인.

[root@localhost /]# nohup echo hello > a.txt
nohup: ignoring input and redirecting stderr to stdout

[root@localhost /]# cat a.txt 

hello


nohup 명령어로 echo hello 명령을 a.txt 파일에 저장. (파일이 없으면 생성된다)


[root@localhost /]# rm -rf nohup.out 

[root@localhost /]# nohup echo hello > /dev/null

nohup: ignoring input and redirecting stderr to stdout

[root@localhost /]# cat nohup.out
cat: nohup.out: 그런 파일이나 디렉터리가 없습니다.

nohup가 수행한 명령을 /dev/null파일로 보내버리면 로그가 남지 않는다.

[root@localhost ~]# nohup mkdir a &

[1] 4602

[root@localhost ~]# ls -ld a
drwxr-xr-x. 2 root root 4096 2017-11-05 20:48 a

nohup & 명령으로 백그라운드로 mkdir a 명령을 수행한다.
화면에 표시된 프로세스는 없지만 , 결과는 a 디렉터리가 생성됨.


'리눅스 > 명령어' 카테고리의 다른 글

[시스템 모니터링 - TOP]  (0) 2017.11.08
[메모리 상태 확인 - vmstat]  (0) 2017.11.05
[프로세스 우선순위 - nice , renice]  (0) 2017.11.05
[파일 시스템 검사 - fsck]  (0) 2017.11.03
[파일시스템 변경 - tune2fs]  (0) 2017.11.03