foreground, background smallsh while (!eof) { input command line; execute command; wait;

6
•foreground, background • smallsh while (!EOF) { input command line; execute command; wait; }

Upload: ronan-mejia

Post on 02-Jan-2016

41 views

Category:

Documents


2 download

DESCRIPTION

foreground, background smallsh while (!EOF) { input command line; execute command; wait; }. smallsh main (p153) userin (p146 ~ 147) - prompt 를 표시하고 입력인자를 읽음 procline  gettok (p149) - gettok 를 사용하여 토큰으로 분리한 후 , 유형 변수를 지정함 - \n, &, ;, argument - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: foreground, background  smallsh while (!EOF) { input command line;       execute command; wait;

•foreground, background

• smallsh

while (!EOF) {

input command line;

execute command;

wait;

}

Page 2: foreground, background  smallsh while (!EOF) { input command line;       execute command; wait;

• smallsh

main (p153)

userin (p146 ~ 147)

- prompt 를 표시하고 입력인자를 읽음

procline gettok (p149)

- gettok 를 사용하여 토큰으로 분리한 후 , 유형 변수를 지정함

- \n, &, ;, argument

runcommand(p152)

- child process 를 생성한 후 입력한 명령어를 수행시킴

- foreground 인 경우 , child process 가 종료할 때까지 기다림

- background 인 경우 , 즉시 종료함

Page 3: foreground, background  smallsh while (!EOF) { input command line;       execute command; wait;

• 실습

- smallsh 을 수정하여 testdata 를 출력하는 명령어를 수행할 수 있도록 함

step1) argc 와 argv 를 이용하여 파일을 읽은 후 출력할 수 있는 프로그램 작성

> ./test8 testdata

위의 명령어를 인식할 수 있도록 항상 실행은 ./ 로 시작

step2) 위의 명령어에 대한 type 을 정의함

step3) runcommand 를 사용하여 background 와 foreground 를 인식할 수

있도록 작성함

수정사항 ) smallsh.h 에 type 정의

userin.c 의 gettok 함수를 정의된 type 을 인식할 수 있도록 수정

procline.c 도 정의된 type 을 가지는 arguments 를 저장할 수 있도록

수정

Page 4: foreground, background  smallsh while (!EOF) { input command line;       execute command; wait;

프로세스 식별번호

• 프로세스 0 – 스와퍼 ( 스케쥴러 )

• 프로세스 1 – 초기화 프로세스 (init)

• getpid(), getppid()

• ( 예제 ) – p156 (test1.c)

• ( 실습 ) – 연습문제 5.11( 두 프로그램으로 구성 )

1) fork 와 exec 를 사용하여 gentemp 를 수행하도록 함

2) gentemp 는 파일 이름의 prefix 를 인수로 입력 받도록 함

Page 5: foreground, background  smallsh while (!EOF) { input command line;       execute command; wait;

프로세스 그룹과 프로세스 그룹 식별번호

• 그림 5.5 (who | awk ‘{print $1}’ | sort –u)

• 프로세스들의 한 집합을 한꺼번에 처리할 때 유리

• 프로세스 그룹은 프로세스 그룹 식별번호에 의해 표시

• 한 프로세스가 프로세스 그룹 식별번호와 동일한 pid 를 가지고 있으면

리더로 간주

• getpgrp 에 의해 프로세스 그룹 식별번호를 획득

• int setpgid(pid_t pid, pid_t pgid)

- 식별번호가 pid 인 프로세스의 그룹 식별자를 pgid 로 설정

- pid 가 0 이면 호출 프로세스의 pid 가 사용

- pid 와 pgid 가 동일하면 리더로 설정

- pgid 가 0 이면 pid 가 프로세스 그룹 식별번호로 설정

Page 6: foreground, background  smallsh while (!EOF) { input command line;       execute command; wait;

환경

• name=something

• showmyenv.c

• setmyenv.c

• getenv(), putenv()

• getuid(), geteuid(), getgid(), getegid()