[AIX 운영 체제와 장치 관리 13] 프로세스 — 포그라운드·백그라운드·데몬·좀비, ps, nice·renice, 취소와 재시작, at·atq 예약, kill
https://archive.horanglab.com/posts/aix-osdev-13
핵심 정리
- 프로세스는 부모-자식 계층을 이루고 시작할 때마다 새 PID를 받습니다. 사용자마다 기본 최대 40개 프로세스를 실행할 수 있습니다.
- 백그라운드 실행은 명령 끝에
&를 붙입니다. 출력이 다른 작업을 방해하므로 파일이나 프린터로 방향을 바꾸는 것이 좋습니다. nice -n(039, 클수록 낮은 우선순위)으로 시작 우선순위를,renice(-2020)로 실행 중 우선순위를 바꿉니다. 높이려면 root 권한이 필요합니다.- INTERRUPT(Ctrl-C)는 포그라운드만 취소합니다. Ctrl-Z로 멈춘 프로세스는
kill -19 PID(CONTINUE)로 백그라운드에서 다시 시작하고fg로 포그라운드로 가져옵니다(Bourne 셸 제외). - at 사용 권한은
at.allow·at.deny로 정하며 둘 다 없으면 root만 쓸 수 있습니다.at -l·atq로 나열,at -r로 제거합니다. kill의 기본 신호는 15(SIGTERM)이고 좀비는 부모를 없애야 사라집니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 6.1 (5.3판과 거의 같음) |
| 원문 | Operating system and device management — 5.3판 329336쪽, 6.1판 133141쪽 |
| 관련 명령어 | ps, nice, renice, kill, fg, at, atq, smit nice·smit renice·smit rmat·smit kill |
| 관련 파일 | /var/adm/cron/at.allow, /var/adm/cron/at.deny |
컴퓨터에서 실제로 실행 중인 프로그램이나 명령을 프로세스라고 합니다.
프로세스는 부모-자식 계층으로 존재합니다. 프로그램이나 명령이 시작한 프로세스는 부모 프로세스이고, 자식 프로세스는 부모 프로세스가 만든 것입니다. 부모 프로세스는 자식 프로세스를 여러 개 가질 수 있지만 자식 프로세스의 부모는 하나뿐입니다.
시스템은 프로세스가 시작할 때마다 프로세스 식별 번호(PID 번호)를 할당합니다. 같은 프로그램을 여러 번 시작하면 매번 다른 PID 번호를 받습니다.
프로세스가 시스템에서 시작되면 쓸 수 있는 시스템 자원의 일부를 씁니다. 프로세스가 둘 이상 실행 중이면 운영 체제에 내장된 스케줄러가 정해진 우선순위에 따라 각 프로세스에 컴퓨터 시간을 나눠 줍니다. 이 우선순위는 nice나 renice 명령으로 바꿀 수 있습니다.
참고: 프로세스 우선순위를 높이려면 root 사용자 권한이 있어야 합니다. 모든 사용자는 자기가 시작할 프로세스의 우선순위를 nice 명령으로, 이미 시작한 프로세스의 우선순위를 renice 명령으로 낮출 수 있습니다.
프로세스의 종류는 다음과 같습니다.
포그라운드와 백그라운드 프로세스
사용자가 시작하거나 사용자와 상호 작용해야 하는 프로세스를 포그라운드 프로세스라고 합니다. 사용자와 상관없이 실행되는 프로세스를 백그라운드 프로세스라고 합니다. 프로그램과 명령은 기본적으로 포그라운드 프로세스로 실행됩니다. 프로세스를 백그라운드에서 실행하려면 프로세스를 시작하는 명령 이름 끝에 앰퍼샌드(&)를 붙입니다.
데몬 프로세스
데몬은 사람의 개입 없이 실행되는 프로세스입니다. 늘 백그라운드에 있으며 언제든 쓸 수 있습니다. 데몬은 보통 시스템이 시작할 때 시작해 시스템이 멈출 때까지 실행됩니다. 데몬 프로세스는 대개 시스템 서비스를 하며, 언제든 둘 이상의 작업이나 사용자가 쓸 수 있습니다. 데몬 프로세스는 root 사용자나 root 셸이 시작하며 root 사용자만 멈출 수 있습니다. 예를 들어 qdaemon 프로세스는 프린터 같은 시스템 자원에 접근하게 해 줍니다. 또 다른 흔한 데몬은 sendmail 데몬입니다.
좀비 프로세스
좀비 프로세스는 더 이상 실행되지 않지만 프로세스 테이블에 여전히 올라 있는(다시 말해 PID 번호가 있는) 죽은 프로세스입니다. 다른 시스템 공간은 할당돼 있지 않습니다. 좀비 프로세스는 강제 종료됐거나 끝났지만, 부모 프로세스가 죽거나 시스템을 종료하고 다시 시작할 때까지 프로세스 테이블에 남아 있습니다. 좀비 프로세스는 ps 명령으로 나열하면 <defunct>로 표시됩니다.
프로세스 시작
디스플레이 스테이션의 시스템 프롬프트에서 프로그램 이름이나 명령 이름을 입력해 포그라운드 프로세스를 시작합니다.
포그라운드 프로세스가 시작되면 끝날 때까지 디스플레이 스테이션에서 사용자와 상호 작용합니다. 프로세스가 끝나거나 사용자가 멈출 때까지 디스플레이 스테이션에서 다른 상호 작용(예를 들어 다른 명령 입력)은 할 수 없습니다.
한 사용자는 한 번에 둘 이상의 프로세스를 실행할 수 있으며, 기본 최대치는 사용자마다 40개입니다.
포그라운드에서 프로세스 시작
포그라운드에서 프로세스를 시작하려면 명령 이름을 알맞은 매개변수·플래그와 함께 입력합니다.
$ CommandName
백그라운드에서 프로세스 시작
백그라운드에서 프로세스를 실행하려면 명령 이름을 알맞은 매개변수·플래그와 함께 입력하고 끝에 앰퍼샌드(&)를 붙입니다.
$ CommandName &
프로세스가 백그라운드에서 실행 중이면 디스플레이 스테이션에서 다른 명령을 입력해 다른 작업을 할 수 있습니다.
일반적으로 백그라운드 프로세스는 실행이 오래 걸리는 명령에 가장 쓸모 있습니다. 그러나 프로세서가 하는 일의 총량을 늘리므로 백그라운드 프로세스는 시스템의 나머지를 느리게 할 수 있습니다.
대부분의 프로세스는 백그라운드에서 실행해도 출력을 표준 출력으로 보냅니다. 방향을 바꾸지 않으면 표준 출력은 디스플레이 장치로 갑니다. 백그라운드 프로세스의 출력이 시스템에서 하는 다른 작업을 방해할 수 있으므로, 백그라운드 프로세스의 출력은 파일이나 프린터로 방향을 바꾸는 것이 보통 좋습니다. 그러면 준비됐을 때 언제든 출력을 볼 수 있습니다.
참고: 어떤 상황에서는 프로세스가 백그라운드에서 실행될 때 포그라운드와 다른 순서로 출력을 만들 수 있습니다. 프로그래머는 fflush 서브루틴으로 프로세스가 포그라운드든 백그라운드든 출력이 올바른 순서로 나오게 할 수 있습니다.
백그라운드 프로세스가 실행 중일 때 ps 명령으로 상태를 확인할 수 있습니다.
프로세스 상태 확인 명령(ps 명령)
시스템이 실행 중이면 언제나 프로세스도 실행 중입니다. ps 명령으로 어떤 프로세스가 실행 중인지 알아보고 그 정보를 볼 수 있습니다.
ps 명령에는 나열할 프로세스와 프로세스마다 보여 줄 정보를 지정하는 여러 플래그가 있습니다.
시스템에서 실행 중인 모든 프로세스를 보려면 프롬프트에서 다음을 입력합니다.
ps -ef
시스템은 다음과 비슷한 정보를 보여 줍니다.
USER PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun 28 - 3:23 /etc/init
root 1588 6963 0 Jun 28 - 0:02 /usr/etc/biod 6
root 2280 1 0 Jun 28 - 1:39 /etc/syncd 60
mary 2413 16998 2 07:57:30 - 0:05 aixterm
mary 11632 16998 0 07:57:31 lft/1 0:01 xbiff
mary 16260 2413 1 07:57:35 pts/1 0:00 /bin/ksh
mary 16469 1 0 07:57:12 lft/1 0:00 ksh /usr/lpp/X11/bin/xinit
mary 19402 16260 20 09:37:21 pts/1 0:00 ps -ef
앞 출력의 열은 다음과 같습니다.
| 열 | 뜻 |
|---|---|
USER |
사용자 로그인 이름 |
PID |
프로세스 ID |
PPID |
부모 프로세스 ID |
C |
프로세스의 CPU 사용률 |
STIME |
프로세스 시작 시각 |
TTY |
프로세스를 제어하는 워크스테이션 |
TIME |
프로세스의 총 실행 시간 |
CMD |
명령 |
앞 예에서 ps -ef 명령의 프로세스 ID는 19402입니다. 부모 프로세스 ID는 16260, 곧 /bin/ksh 명령입니다.
목록이 아주 길면 윗부분이 화면 밖으로 밀려납니다. 목록을 한 페이지(화면)씩 보려면 ps 명령을 pg 명령으로 파이프합니다. 프롬프트에서 다음을 입력합니다.
ps -ef | pg
시스템에서 실행 중인 모든 프로세스의 상태 정보를 보려면 프롬프트에서 다음을 입력합니다.
ps gv
이 형식은 활성 프로세스마다 여러 통계를 나열합니다. 출력은 다음과 비슷합니다.
PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND
0 - A 0:44 7 8 8 xx 0 0 0.0 0.0 swapper
1 - A 1:29 518 244 140 xx 21 24 0.1 1.0 /etc/init
771 - A 1:22 0 16 16 xx 0 0 0.0 0.0 kproc
1028 - A 0:00 10 16 8 xx 0 0 0.0 0.0 kproc
1503 - A 0:33 127 16 8 xx 0 0 0.0 0.0 kproc
1679 - A 1:03 282 192 12 32768 130 0 0.7 0.0 pcidossvr
2089 - A 0:22 918 72 28 xx 1 4 0.0 0.0 /etc/sync
2784 - A 0:00 9 16 8 xx 0 0 0.0 0.0 kproc
2816 - A 5:59 6436 2664 616 8 852 156 0.4 4.0 /usr/lpp/
3115 - A 0:27 955 264 128 xx 39 36 0.0 1.0 /usr/lib/
3451 - A 0:00 0 16 8 xx 0 0 0.0 0.0 kproc
3812 - A 0:00 21 128 12 32768 34 0 0.0 0.0 usr/lib/lpd/
3970 - A 0:00 0 16 8 xx 0 0 0.0 0.0 kproc
4267 - A 0:01 169 132 72 32768 16 16 0.0 0.0 /etc/sysl
4514 lft/0 A 0:00 60 200 72 xx 39 60 0.0 0.0 /etc/gett
4776 pts/3 A 0:02 250 108 280 8 303 268 0.0 2.0 -ksh
5050 - A 0:09 1200 424 132 32768 243 56 0.0 1.0 /usr/sbin
5322 - A 0:27 1299 156 192 xx 24 24 0.0 1.0 /etc/cron
5590 - A 0:00 2 100 12 32768 11 0 0.0 0.0 /etc/writ
5749 - A 0:00 0 208 12 xx 13 0 0.0 0.0 /usr/lpp/
6111 - T 0:00 66 108 12 32768 47 0 0.0 0.0 /usr/lpp/
전체 구문은 Commands Reference, Volume 4의 ps 명령을 봅니다.
프로세스의 초기 우선순위 설정(nice 명령)
프로세스의 초기 우선순위를 기본 스케줄링 우선순위보다 낮은 값으로 설정할 수 있습니다.
그러려면 nice 명령으로 프로세스를 시작합니다.
참고: 프로세스를 기본 스케줄링 우선순위보다 높은 우선순위로 실행하려면 root 사용자 권한이 있어야 합니다.
프로세스의 초기 우선순위를 설정하려면 다음을 입력합니다.
nice -n Number CommandString
Number는 0부터 39까지이며 39가 가장 낮은 우선순위입니다. nice 값은 프로세스의 시스템 스케줄링 우선순위를 나타내는 십진 값입니다. 숫자가 클수록 우선순위가 낮습니다. 0을 쓰면 프로세스는 기본 스케줄링 우선순위로 실행됩니다. CommandString은 실행할 명령과 플래그, 매개변수입니다.
전체 구문은 Commands Reference, Volume 4의 nice 명령을 봅니다.
smit nice 명령으로도 이 작업을 할 수 있습니다.
실행 중인 프로세스의 우선순위 바꾸기(renice 명령)
명령행에서 renice 명령으로 실행 중인 프로세스의 스케줄링 우선순위를 기본 스케줄링 우선순위보다 낮거나 높은 값으로 바꿀 수 있습니다. 이 명령은 프로세스의 nice 값을 바꿉니다.
참고: 프로세스를 더 높은 우선순위로 실행하거나 자기가 시작하지 않은 프로세스의 우선순위를 바꾸려면 root 사용자 권한이 있어야 합니다.
실행 중인 프로세스의 우선순위를 바꾸려면 다음을 입력합니다.
renice Priority -p ProcessID
Priority는 -20부터 20까지의 수입니다. 숫자가 클수록 우선순위가 낮습니다. 0을 쓰면 프로세스는 기본 스케줄링 우선순위로 실행됩니다. ProcessID는 우선순위를 바꿀 프로세스의 PID입니다.
smit renice 명령으로도 이 작업을 할 수 있습니다.
포그라운드 프로세스 취소
포그라운드 프로세스를 시작한 뒤 끝까지 실행하지 않기로 했다면 INTERRUPT를 눌러 취소할 수 있습니다. 보통 Ctrl-C나 Ctrl-Backspace입니다.
참고: INTERRUPT(Ctrl-C)는 백그라운드 프로세스를 취소하지 않습니다. 백그라운드 프로세스를 취소하려면 kill 명령을 써야 합니다.
간단한 명령은 대부분 너무 빨리 실행돼 취소할 틈도 없이 끝납니다. 그래서 이 절의 예에서는 실행에 몇 초 이상 걸리는 명령 find / -type f를 씁니다. 이 명령은 시스템의 모든 파일 경로 이름을 보여 줍니다. 이 절을 따라 하려고 find 명령을 공부할 필요는 없습니다. 여기서는 프로세스를 다루는 방법을 보여 주려고 쓸 뿐입니다.
다음 예에서는 find 명령이 프로세스를 시작합니다. 프로세스가 몇 초 실행된 뒤 INTERRUPT 키를 눌러 취소할 수 있습니다.
$ find / -type f
/usr/sbin/acct/lastlogin
/usr/sbin/acct/prctmp
/usr/sbin/acct/prdaily
/usr/sbin/acct/runacct
/usr/sbin/acct/sdisk
/usr/sbin/acct/shutacct INTERRUPT (Ctrl-C)
$ _
시스템은 화면에 프롬프트를 돌려줍니다. 이제 다른 명령을 입력할 수 있습니다.
관련 작업
- 터미널의 제어 키 할당 목록(stty 명령) — 터미널 설정을 보려면 stty 명령을 씁니다. 특히 터미널이 제어 키로 어떤 키를 쓰는지 눈여겨봅니다.
포그라운드 프로세스를 멈추는 키보드 명령
프로세스가 멈췄지만 프로세스 ID(PID)가 프로세스 테이블에서 지워지지 않을 수 있습니다. 키보드에서 Ctrl-Z를 눌러 포그라운드 프로세스를 멈출 수 있습니다.
참고: Ctrl-Z는 Korn 셸(ksh)과 C 셸(csh)에서 동작하며 Bourne 셸(bsh)에서는 동작하지 않습니다.
멈춘 프로세스 다시 시작
이 절차는 Ctrl-Z로 멈춘 프로세스를 다시 시작하는 방법을 설명합니다.
참고: Ctrl-Z는 Korn 셸(ksh)과 C 셸(csh)에서 동작하며 Bourne 셸(bsh)에서는 동작하지 않습니다. 멈춘 프로세스를 다시 시작하려면 그 프로세스를 시작한 사용자이거나 root 사용자 권한이 있어야 합니다.
- 시스템에서 실행 중이거나 멈춘(강제 종료된 것은 빼고) 모든 프로세스를 보려면 다음을 입력합니다.
ps -ef
다시 시작하려는 프로세스일 가능성이 큰 것만 나오게 이 명령을 grep 명령으로 파이프할 수 있습니다. 예를 들어 vi 세션을 다시 시작하려면 다음을 입력할 수 있습니다.
ps -ef | grep vi
이 명령은 ps 명령 출력에서 vi라는 단어가 든 줄만 보여 줍니다. 출력은 다음과 비슷합니다.
UID PID PPID C STIME TTY TIME COMMAND
root 1234 13682 0 00:59:53 - 0:01 vi test
root 14277 13682 1 01:00:34 - 0:00 grep vi
- ps 명령 출력에서 다시 시작할 프로세스를 찾아 PID 번호를 적어 둡니다. 예에서 PID는
1234입니다. - 멈춘 프로세스에 CONTINUE 신호를 보내려면 다음을 입력합니다.
kill -19 1234
1234 자리에 자기 프로세스의 PID를 넣습니다. -19는 CONTINUE 신호를 뜻합니다. 이 명령은 프로세스를 백그라운드에서 다시 시작합니다. 프로세스가 백그라운드에서 실행될 수 있으면 절차는 끝입니다. (vi 세션처럼) 포그라운드에서 실행돼야 하면 다음 단계로 갑니다.
4. 프로세스를 포그라운드로 가져오려면 다음을 입력합니다.
fg 1234
이번에도 1234 자리에 자기 프로세스의 PID를 넣습니다. 이제 프로세스가 포그라운드에서 실행됩니다(vi 편집 세션으로 돌아와 있습니다).
프로세스를 나중에 실행하도록 예약
프로세스를 정한 시각에 백그라운드에서 실행되는 일괄 처리 프로세스로 설정할 수 있습니다.
at와 smit 명령으로 나중에 실행할 명령 이름을 입력하고 언제 실행할지 지정할 수 있습니다.
참고: /var/adm/cron/at.allow와 /var/adm/cron/at.deny 파일이 at 명령 사용 여부를 정합니다. root 사용자 권한이 있는 사람이 이 파일을 만들고 편집하고 지울 수 있습니다. 이 파일의 항목은 사용자 로그인 이름이며 한 줄에 하나씩 씁니다. 다음은 at.allow 파일의 예입니다.
root
nick
dee
sarah
at.allow 파일이 있으면 거기 로그인 이름이 나열된 사용자만 at 명령을 쓸 수 있습니다. 시스템 관리자는 at.deny 파일에 사용자 로그인 이름을 올려 그 사용자가 at 명령을 쓰지 못하게 명시적으로 막을 수 있습니다. at.deny 파일만 있으면 그 파일에 이름이 없는 사용자는 누구나 at 명령을 쓸 수 있습니다.
다음 가운데 하나라도 해당하면 at 명령을 쓸 수 없습니다.
at.allow파일과at.deny파일이 둘 다 없습니다(root 사용자만 허용).at.allow파일이 있지만 사용자 로그인 이름이 없습니다.at.deny파일이 있고 사용자 로그인 이름이 들어 있습니다.
at.allow 파일이 없고 at.deny 파일도 없거나 비어 있으면 root 사용자 권한이 있는 사람만 at 명령으로 작업을 제출할 수 있습니다.
at 명령 구문으로 프로세스를 실행할 때를 날짜 문자열, 시각과 요일 문자열, 증분 문자열로 지정할 수 있습니다. 쓸 셸이나 큐도 지정할 수 있습니다. 다음 예는 이 명령의 전형적인 쓰임을 보여 줍니다.
예를 들어 로그인 이름이 joyce이고 자정에 실행할 WorkReport라는 스크립트가 있으면 다음처럼 합니다.
- 프로그램을 실행하기 시작할 시각을 입력합니다.
at midnight
- 실행할 프로그램 이름을 입력하고 이름마다 Enter를 누릅니다. 마지막 이름을 입력한 뒤 파일 끝 문자(Ctrl-D)를 눌러 목록이 끝났음을 알립니다.
WorkReport^D
Ctrl-D를 누르면 시스템은 다음과 비슷한 정보를 보여 줍니다.
job joyce.741502800.a at Fri Jul 6 00:00:00 CDT 2002.
프로그램 WorkReport는 작업 번호 joyce.741502800.a를 받고 7월 6일 자정에 실행됩니다.
3. 나중에 실행하도록 보낸 프로그램을 나열하려면 다음을 입력합니다.
at -l
시스템은 다음과 비슷한 정보를 보여 줍니다.
joyce.741502800.a Fri Jul 6 00:00:00 CDT 2002
전체 구문은 at 명령을 봅니다.
관련 작업
- 예약한 모든 프로세스 나열(at나 atq 명령) — at 명령이나 atq 명령에
-l플래그를 써서 예약한 모든 프로세스를 나열합니다. - 예약에서 프로세스 제거 — at 명령에
-r플래그를 써서 예약한 프로세스를 제거할 수 있습니다.
예약한 모든 프로세스 나열(at나 atq 명령)
at 명령이나 atq 명령에 -l 플래그를 써서 예약한 모든 프로세스를 나열합니다.
두 명령은 같은 출력을 내지만, atq 명령은 at 명령을 실행한 시각과 같은 순서로 프로세스를 정렬할 수 있고 큐의 프로세스 수만 보여 줄 수도 있습니다.
예약한 모든 프로세스는 다음 방법으로 나열할 수 있습니다.
- 명령행에서 at 명령으로
- atq 명령으로
at 명령
예약한 프로세스를 나열하려면 다음을 입력합니다.
at -l
이 명령은 자기 큐의 예약된 모든 프로세스를 나열합니다. root 사용자이면 모든 사용자의 예약된 프로세스를 나열합니다. 구문의 자세한 내용은 at 명령을 봅니다.
atq 명령
atq 명령을 쓰는 예는 다음과 같습니다.
- 큐의 예약된 모든 프로세스를 나열하려면 다음을 입력합니다.
atq
- root 사용자이면 다음을 입력해 특정 사용자 큐의 예약된 프로세스를 나열할 수 있습니다.
atq UserName
- 큐의 예약된 프로세스 수를 나열하려면 다음을 입력합니다.
atq -n
관련 작업
- 프로세스를 나중에 실행하도록 예약 — 프로세스를 정한 시각에 백그라운드에서 실행되는 일괄 처리 프로세스로 설정할 수 있습니다.
- 예약에서 프로세스 제거 — at 명령에
-r플래그를 써서 예약한 프로세스를 제거할 수 있습니다.
예약에서 프로세스 제거
at 명령에 -r 플래그를 써서 예약한 프로세스를 제거할 수 있습니다.
at나 atq 명령 쓰는 예는 다음과 같습니다.
- 예약한 프로세스를 제거하려면 그 프로세스 번호를 알아야 합니다. 프로세스 번호는
at -l명령이나 atq 명령으로 얻을 수 있습니다. - 제거할 프로세스 번호를 알면 다음을 입력합니다.
at -r ProcessNumber
smit rmat 명령으로도 이 작업을 할 수 있습니다.
관련 작업
- 예약한 모든 프로세스 나열(at나 atq 명령) — at 명령이나 atq 명령에
-l플래그를 써서 예약한 모든 프로세스를 나열합니다. - 프로세스를 나중에 실행하도록 예약 — 프로세스를 정한 시각에 백그라운드에서 실행되는 일괄 처리 프로세스로 설정할 수 있습니다.
백그라운드 프로세스 없애기(kill 명령)
INTERRUPT로 포그라운드 프로세스가 멈추지 않거나, 백그라운드 프로세스를 시작한 뒤 끝까지 실행하지 않기로 했다면 kill 명령으로 프로세스를 취소할 수 있습니다.
kill 명령으로 프로세스를 취소하려면 먼저 그 PID 번호를 알아야 합니다. kill 명령의 일반 형식은 다음과 같습니다.
kill ProcessID
참고
- 프로세스를 없애려면 root 사용자 권한이 있거나 그 프로세스를 시작한 사용자여야 합니다. kill 명령이 프로세스에 보내는 기본 신호는 -15(SIGTERM)입니다.
- 좀비 프로세스를 없애려면 그 부모 프로세스를 없애야 합니다.
- ps 명령으로 없앨 프로세스의 ID를 알아냅니다. 원하는 프로세스만 나오게 이 명령을 grep 명령으로 파이프할 수 있습니다. 예를 들어 vi 세션의 프로세스 ID를 알려면 다음을 입력할 수 있습니다.
ps -l | grep vi
- 다음 예에서는 find 명령을 백그라운드에서 실행하도록 내린 뒤 프로세스를 취소하기로 합니다. ps 명령으로 PID 번호를 나열합니다.
$ find / -type f > dir.paths &
[1] 21593
$ ps
PID TTY TIME COMMAND
1627 pts3 0:00 ps
5461 pts3 0:00 ksh
17565 pts3 0:00 -ksh
21593 pts3 0:00 find / -type f
$ kill 21593
$ ps
PID TTY TIME COMMAND
1627 pts3 0:00 ps
5461 pts3 0:00 ksh
17565 pts3 0:00 -ksh
[1] + Terminated 21593 find / -type f > dir.paths &
kill 21593 명령은 백그라운드 find 프로세스를 끝내고, 두 번째 ps 명령은 PID 21593에 대한 상태 정보를 돌려주지 않습니다. 시스템은 다음 명령을 입력할 때까지 종료 메시지를 보여 주지 않으며, 그 명령이 cd면 보여 주지 않습니다. kill 명령으로 백그라운드 프로세스를 취소할 수 있습니다. 프로세스를 실수로 백그라운드에 넣었거나 실행이 너무 오래 걸린다는 것을 깨달았을 때 이렇게 할 수 있습니다.
전체 구문은 Commands Reference, Volume 3의 kill 명령을 봅니다.
다음을 입력하면 smit에서도 kill 명령을 쓸 수 있습니다.
smit kill
영어 원문
Processes
A program or command that is actually running on the computer is referred to as a process.
Processes exist in parent-child hierarchies. A process started by a program or command is a parent process; a child process is the product of the parent process. A parent process can have several child processes, but a child process can have only one parent.
The system assigns a process identification number (PID number) to each process when it starts. If you start the same program several times, it will have a different PID number each time.
When a process is started on a system, the process uses a part of the available system resources. When more than one process is running, a scheduler that is built into the operating system gives each process a share of the computer's time, based on established priorities. These priorities can be changed by using the nice or renice commands.
Note: To change a process priority to a higher one, you must have root user authority. All users can lower priorities on a process they start by using the nice command or on a process they have already started, by using the renice command.
The following list describes the types of processes:
Foreground and background processes
Processes that require a user to start them or to interact with them are called foreground processes. Processes that are run independently of a user are referred to as background processes. Programs and commands run as foreground processes by default. To run a process in the background, place an ampersand (&) at the end of the command name that you use to start the process.
Daemon processes
Daemons are processes that run unattended. They are constantly in the background and are available at all times. Daemons are usually started when the system starts, and they run until the system stops. A daemon process typically performs system services and is available at all times to more than one task or user. Daemon processes are started by the root user or root shell and can be stopped only by the root user. For example, the qdaemon process provides access to system resources such as printers. Another common daemon is the sendmail daemon.
Zombie processes
A zombie process is a dead process that is no longer executing but is still recognized in the process table (in other words, it has a PID number). It has no other system space allocated to it. Zombie processes have been killed or have exited and continue to exist in the process table until the parent process dies or the system is shut down and restarted. Zombie processes display as <defunct> when listed by the ps command.
Process startup
You start a foreground process from a display station by either entering a program name or command name at the system prompt.
After a foreground process has started, the process interacts with you at your display station until it is complete. No other interaction (for example, entering another command) can take place at the display station until the process is finished or you halt it.
A single user can run more than one process at a time, up to a default maximum of 40 processes per user.
Starting a process in the foreground
To start a process in the foreground, enter the name of the command with the appropriate parameters and flags:
$ CommandName
Starting a process in the background
To run a process in the background, type the name of the command with the appropriate parameters and flags, followed by an ampersand (&):
$ CommandName &
When a process is running in the background, you can perform additional tasks by entering other commands at your display station.
Generally, background processes are most useful for commands that take a long time to run. However, because they increase the total amount of work the processor is doing, background processes can slow down the rest of the system.
Most processes direct their output to standard output, even when they run in the background. Unless redirected, standard output goes to the display device. Because the output from a background process can interfere with your other work on the system, it is usually good practice to redirect the output of a background process to a file or a printer. You can then look at the output whenever you are ready.
Note: Under certain circumstances, a process might generate its output in a different sequence when run in the background than when run in the foreground. Programmers might want to use the fflush subroutine to ensure that output occurs in the correct order regardless of whether the process runs in foreground or background.
While a background process is running, you can check its status with the ps command.
Command to check the process status (ps command)
Any time the system is running, processes are also running. You can use the ps command to find out which processes are running and display information about those processes.
The ps command has several flags that enable you to specify which processes to list and what information to display about each process.
To show all processes running on your system, at the prompt, type the following:
ps -ef
The system displays information similar to the following:
USER PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun 28 - 3:23 /etc/init
root 1588 6963 0 Jun 28 - 0:02 /usr/etc/biod 6
root 2280 1 0 Jun 28 - 1:39 /etc/syncd 60
mary 2413 16998 2 07:57:30 - 0:05 aixterm
mary 11632 16998 0 07:57:31 lft/1 0:01 xbiff
mary 16260 2413 1 07:57:35 pts/1 0:00 /bin/ksh
mary 16469 1 0 07:57:12 lft/1 0:00 ksh /usr/lpp/X11/bin/xinit
mary 19402 16260 20 09:37:21 pts/1 0:00 ps -ef
The columns in the previous output are defined as follows:
USER— User login namePID— Process IDPPID— Parent process IDC— CPU utilization of processSTIME— Start time of processTTY— Controlling workstation for the processTIME— Total execution time for the processCMD— Command
In the previous example, the process ID for the ps -ef command is 19402. Its parent process ID is 16260, the /bin/ksh command.
If the listing is very long, the top portion scrolls off the screen. To display the listing one page (screen) at a time, pipe the ps command to the pg command. At the prompt, type the following:
ps -ef | pg
To display status information of all processes running on your system, at the prompt, type the following:
ps gv
This form of the command lists a number of statistics for each active process. Output from this command looks similar to the following:
(22줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
See the ps command in the Commands Reference, Volume 4 for the complete syntax.
Setting the initial priority of a process (nice command)
You can set the initial priority of a process to a value lower than the base scheduling priority.
To set the initial priority of a process to a value lower than the base scheduling priority, use the nice command to start the process.
Note: To run a process at a higher priority than the base scheduling priority, you must have root user authority.
To set the initial priority of a process, type the following:
nice -n Number CommandString
where Number is in the range of 0 to 39, with 39 being the lowest priority. The nice value is the decimal value of the system-scheduling priority of a process. The higher the number, the lower the priority. If you use zero, the process will run at its base scheduling priority. CommandString is the command and flags and parameters you want to run.
See the nice command in the Commands Reference, Volume 4 for the complete syntax.
You can also use the smit nice command to perform this task.
Changing the priority of a running process (renice command):
You can change the scheduling priority of a running process to a value lower or higher than the base scheduling priority by using the renice command from the command line. This command changes the nice value of a process.
Note: To run a process at a higher priority or to change the priority for a process that you did not start, you must have root user authority.
To change the priority of a running process, type the following:
renice Priority -p ProcessID
where Priority is a number in the range of -20 to 20. The higher the number, the lower the priority. If you use zero, the process will run at its base scheduling priority. ProcessID is the PID for which you want to change the priority.
You can also use the smit renice command to perform this task.
Foreground process cancellation
If you start a foreground process and then decide that you do not want it to finish, you can cancel it by pressing INTERRUPT. This is usually Ctrl-C or Ctrl-Backspace.
Note: INTERRUPT (Ctrl-C) does not cancel background processes. To cancel a background process, you must use the kill command.
Most simple commands run so quickly that they finish before you have time to cancel them. The examples in this section, therefore, use a command that takes more than a few seconds to run: find / -type f. This command displays the path names for all files on your system. You do not need to study the find command in order to complete this section; it is used here simply to demonstrate how to work with processes.
In the following example, the find command starts a process. After the process runs for a few seconds, you can cancel it by pressing the INTERRUPT key:
$ find / -type f
/usr/sbin/acct/lastlogin
/usr/sbin/acct/prctmp
/usr/sbin/acct/prdaily
/usr/sbin/acct/runacct
/usr/sbin/acct/sdisk
/usr/sbin/acct/shutacct INTERRUPT (Ctrl-C)
$ _
The system returns the prompt to the screen. Now you can enter another command.
Related tasks
List of control key assignments for your terminal (stty command) To display your terminal settings, use the stty command. Note especially which keys your terminal uses for control keys.
Keyboard command to stop a foreground process
It is possible for a process to be stopped but not have its process ID (PID) removed from the process table. You can stop a foreground process by pressing Ctrl-Z from the keyboard.
Note: Ctrl-Z works in the Korn shell (ksh) and C shell (csh), but not in the Bourne shell (bsh).
Restarting a stopped process
This procedure describes how to restart a process that has been stopped with a Ctrl-Z.
Note: Ctrl-Z works in the Korn shell (ksh) and C shell (csh), but not in the Bourne shell (bsh). To restart a stopped process, you must either be the user who started the process or have root user authority.
- To show all the processes running or stopped but not those killed on your system, type the following:
ps -ef
You might want to pipe this command through a grep command to restrict the list to those processes most likely to be the one you want to restart. For example, if you want to restart a vi session, you could type the following:
ps -ef | grep vi
This command would display only those lines from the ps command output that contained the word vi. The output would look something like this:
UID PID PPID C STIME TTY TIME COMMAND
root 1234 13682 0 00:59:53 - 0:01 vi test
root 14277 13682 1 01:00:34 - 0:00 grep vi
In the ps command output, find the process you want to restart and note its PID number. In the example, the PID is
1234.To send the CONTINUE signal to the stopped process, type the following:
kill -19 1234
Substitute the PID of your process for the 1234. The -19 indicates the CONTINUE signal. This command restarts the process in the background. If the process can run in the background, you are finished with the procedure. If the process must run in the foreground (as a vi session would), you must proceed with the next step.
- To bring the process in to the foreground, type the following:
fg 1234
Once again, substitute the PID of your process for the 1234. Your process should now be running in the foreground. (You are now in your vi edit session).
Scheduling a process for later operation
You can set up a process as a batch process to run in the background at a scheduled time.
The at and smit commands let you enter the names of commands to be run at a later time and allow you to specify when the commands should be run.
Note: The /var/adm/cron/at.allow and /var/adm/cron/at.deny files control whether you can use the at command. A person with root user authority can create, edit, or delete these files. Entries in these files are user login names with one name to a line. The following is an example of an at.allow file:
root
nick
dee
sarah
If the at.allow file exists, only users whose login names are listed in it can use the at command. A system administrator can explicitly stop a user from using the at command by listing the user's login name, in the at.deny file. If only the at.deny file exists, any user whose name does not appear in the file can use the at command.
You cannot use the at command if any one of the following is true:
The
at.allowfile and theat.denyfile do not exist (allows root user only).The
at.allowfile exists but the user's login name is not listed in it.The
at.denyfile exists and the user's login name is listed in it.
If the at.allow file does not exist and the at.deny file does not exist or is empty, only someone with root user authority can submit a job with the at command.
The at command syntax allows you to specify a date string, a time and day string, or an increment string for when you want the process to run. It also allows you to specify which shell or queue to use. The following examples show some typical uses of the command.
For example, if your login name is joyce and you have a script named WorkReport that you want to run at midnight, do the following:
- Type the time you want the program to start running:
at midnight
- Type the names of the programs to run, pressing Enter after each name. After typing the surname, press the end-of-file character (Ctrl-D) to signal the end of the list.
WorkReport^D
After you press Ctrl-D, the system displays information similar to the following:
job joyce.741502800.a at Fri Jul 6 00:00:00 CDT 2002.
The program WorkReport is given the job number joyce.741502800.a and will run at midnight, July 6.
- To list the programs you have sent to be run later, type the following:
at -l
The system displays information similar to the following:
joyce.741502800.a Fri Jul 6 00:00:00 CDT 2002
See the at command for the complete syntax.
Related tasks
“Listing all scheduled processes (at or atq command)” Use the -l flag with the at command or with the atq command to list all scheduled processes. Removing a process from the schedule You can remove a scheduled process with the at command using the -r flag.
Listing all scheduled processes (at or atq command)
Use the -l flag with the at command or with the atq command to list all scheduled processes.
Both commands give the same output; however, the atq command can order the processes in the same amount of time that the at command is issued and displays only the number of processes in the queue.
You can list all scheduled processes in the following ways:
With the at command from the command line
With the atq command
at command
To list the scheduled processes, type the following:
at -l
This command lists all the scheduled processes in your queue. If you are a root user, this command lists all the scheduled processes for all users. For complete details of the syntax, see the at command.
atq command
See the following examples on how to use the atq command:
- To list all scheduled processes in the queue, type the following:
atq
- If you are a root user, you can list the scheduled processes in a particular user's queue by typing:
atq UserName
- To list the number of scheduled processes in the queue, type the following:
atq -n
Related tasks
Scheduling a process for later operation You can set up a process as a batch process to run in the background at a scheduled time. “Removing a process from the schedule” You can remove a scheduled process with the at command using the -r flag.
Removing a process from the schedule
You can remove a scheduled process with the at command using the -r flag.
See the following example on how to use the at or atq command:
To remove a scheduled process, you must know its process number. You can obtain the process number by using the at
-lcommand or the atq command.When you know the number of the process you want to remove, type the following:
at -r ProcessNumber
You can also use the smit rmat command to perform this task.
Related tasks
Listing all scheduled processes (at or atq command) Use the -l flag with the at command or with the atq command to list all scheduled processes. Scheduling a process for later operation You can set up a process as a batch process to run in the background at a scheduled time.
Removing a background process (kill command)
If INTERRUPT does not halt your foreground process or if you decide, after starting a background process, that you do not want the process to finish, you can cancel the process with the kill command.
Before you can cancel a process using the kill command, you must know its PID number. The general format for the kill command is as follows:
kill ProcessID
Note
To remove a process, you must have root user authority or be the user who started the process. The default signal to a process from the kill command is -15 (SIGTERM).
To remove a zombie process, you must remove its parent process.
- Use the ps command to determine the process ID of the process you want to remove. You might want to pipe this command through a grep command to list only the process you want. For example, if you want the process ID of a vi session, you could type the following:
ps -l | grep vi
- In the following example, you issue the find command to run in the background. You then decide to cancel the process. Issue the ps command to list the PID numbers.
(15줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The command kill 21593 ends the background find process, and the second ps command returns no status information about PID 21593. The system does not display the termination message until you enter your next command, unless that command is cd. The kill command lets you cancel background processes. You might want to do this if you realize that you have mistakenly put a process in the background or that a process is taking too long to run.
See the kill command in the Commands Reference, Volume 3 for the complete syntax.
The kill command can also used in smit by typing:
smit kill
명령과 프로세스의 명령 요약
다음은 명령과 프로세스에 쓰는 명령입니다.
표 55. 명령에 관한 명령 요약
| 명령 | 설명 |
|---|---|
| alias | 별명 목록을 표준 출력에 출력하는 셸 명령 |
| history | 기록 이벤트 목록을 보여 주는 셸 명령 |
| man | 명령, 서브루틴, 파일에 관한 정보를 온라인으로 보여 줌 |
| wsm | 웹 브라우저에서 시스템 관리를 함 |
| whatis | 명령이 하는 기능을 설명함 |
| whereis | 설치한 프로그램의 소스, 바이너리, 매뉴얼을 찾음 |
표 56. 프로세스에 관한 명령 요약
| 명령 | 설명 |
|---|---|
| at | 명령을 나중에 실행하거나, 예약한 모든 프로세스를 나열하거나, 예약에서 프로세스를 제거함 |
| atq | 실행을 기다리는 작업 큐를 보여 줌 |
| kill | 실행 중인 프로세스에 신호를 보냄 |
| nice | 명령을 더 낮거나 높은 우선순위로 실행함 |
| ps | 프로세스의 현재 상태를 보여 줌 |
| renice | 실행 중인 프로세스의 우선순위를 바꿈 |
영어 원문
Command summary for commands and processes
The following are commands for commands and processes.
Table 55. Command summary for commands
- alias — Shell command that prints a list of aliases to standard output
- history — Shell command that displays the history event list
- man — Displays information about commands, subroutines, and files online
- wsm — Performs system management from a web browser
- whatis — Describes the function a command performs
- whereis — Locates the source, binary, or manual for installed programs
Table 56. Command summary for processes
- at — Runs commands at a later time, lists all scheduled processes, or removes a process from the schedule
- atq — Displays the queue of jobs waiting to be run
- kill — Sends a signal to running processes
- nice — Runs a command at a lower or higher priority
- ps — Shows current status of processes
- renice — Alters priority of running processes