l command sequence 1 n date who pwd

  • Slides: 43
Download presentation

복합 명령어 l 명령어 열(command sequence) $ 명령어 1; … ; 명령어n $ date;

복합 명령어 l 명령어 열(command sequence) $ 명령어 1; … ; 명령어n $ date; who; pwd l 명령어 그룹(command group) $ (명령어 1; … ; 명령어n) $ date; who; pwd > out 1. txt $ (date; who; pwd) > out 2. txt 5

후면 처리 예 $ (sleep 100; echo done) & [1] 8320 $ find. -name

후면 처리 예 $ (sleep 100; echo done) & [1] 8320 $ find. -name test. c -print & [2] 8325 $ jobs [1] + Running ( sleep 100; echo done ) [2] - Running find. -name test. c –print l l l $ fg %작업번호 l $ fg %1 ( sleep 100; echo done ) 후면처리 입출력 l $ find. -name test. c -print > find. txt & $ find. -name test. c -print | mail chang & $ wc < inputfile & 7

프로세스(process) l l l 실행중인 프로그램을 프로세스(process)라고 부른다. 각 프로세스는 유일한 프로세스 번호 PID를

프로세스(process) l l l 실행중인 프로그램을 프로세스(process)라고 부른다. 각 프로세스는 유일한 프로세스 번호 PID를 갖는다. ps 명령어를 사용하여 나의 프로세스들을 볼 수 있다. $ ps PID TTY TIME CMD 8695 pts/3 00: 00 csh 8720 pts/3 00: 00 ps $ ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND chang 8695 0. 0 5252 1728 pts/3 Ss 11: 12 0: 00 -csh chang 8793 0. 0 4252 940 pts/3 R+ 11: 15 0: 00 ps u 8

args. c #include <stdio. h> /* 모든 명령줄 인수와 환경 변수를 프린트한다. */ int

args. c #include <stdio. h> /* 모든 명령줄 인수와 환경 변수를 프린트한다. */ int main(int argc, char *argv[]) { int i; for (i = 0; i < argc; i++) /* 모든 명령줄 인수 프린트 */ printf("argv[%d]: %s n", i, argv[i]); exit(0); } 18

environ. c #include <stdio. h> /* 모든 명령줄 인수와 환경 변수를 프린트한다. */ int

environ. c #include <stdio. h> /* 모든 명령줄 인수와 환경 변수를 프린트한다. */ int main(int argc, char *argv[]) { char **ptr; extern char **environ; for (ptr = environ; *ptr != 0; ptr++) /* 모든 환경 변수 값 프린트*/ printf("%s n", *ptr); exit(0); } 19

printenv. c #include <stdio. h> #include <stdlib. h> /* 환경 변수를 3개 프린트한다. */

printenv. c #include <stdio. h> #include <stdlib. h> /* 환경 변수를 3개 프린트한다. */ int main(int argc, char *argv[]) { char *ptr; ptr = getenv("HOME"); printf("HOME = %s n", ptr); ptr = getenv("SHELL"); printf("SHELL = %s n", ptr); ptr = getenv("PATH"); printf("PATH = %s n", ptr); } exit(0); 21

atexit() #include <stdlib. h> void atexit(void (*func)(void)); returns: 0 if OK, nonzero on error

atexit() #include <stdlib. h> void atexit(void (*func)(void)); returns: 0 if OK, nonzero on error l exit 처리기를 등록한다 § l func § § l 26 프로세스당 32개까지 exit 처리기 함수 포인터(이름) exit() 는 exit handler 들을 등록된 역순으로 호출한다 © 숙대 창병모

C 프로그램 시작 및 종료 call (do ex no it t re tur n)

C 프로그램 시작 및 종료 call (do ex no it t re tur n) es return ll urn o o _exit handler ca ret n es …… call ) (d rn retu t turn i ex t re call C start-up routine exit handler l cal exit main function (does not return) function return _exit user function return _exit standard I/O cleanup exec kernel 27 © 숙대 창병모 user process

exit 처리기 예 1 #include <stdio. h> 13 static void exit_handler 1(void) { 2

exit 처리기 예 1 #include <stdio. h> 13 static void exit_handler 1(void) { 2 static void my_exit 1(void), 14 3 15 } my_exit 2(void); printf("첫 번째 exit 처리기n"); 4 int main(void) { 16 5 if (atexit(exit_handler 1) != 0) 17 static void exit_handler 2(void) { perror("exit_handler 1 등록할 수 없음"); 18 printf("두 번째 exit 처리기n"); 19 } 7 if (atexit(exit_handler 2) != 0) 6 8 perror("exit_handler 2 등록할 수 없음"); 9 printf("main 끝 n"); 10 exit(0); 11 } 12 28 © 숙대 창병모

uid. c #include <stdio. h> #include <pwd. h> #include <grp. h> /* 사용자 ID를

uid. c #include <stdio. h> #include <pwd. h> #include <grp. h> /* 사용자 ID를 출력한다. */ int main() { int pid; printf("나의 실제 사용자 ID : %d(%s) n", getuid(), getpwuid(getuid())->pw_name); printf("나의 유효 사용자 ID : %d(%s) n", geteuid(), getpwuid(geteuid())->pw_name); printf("나의 실제 그룹 ID : %d(%s) n", getgid(), getgrgid(getgid())->gr_name); printf("나의 유효 그룹 ID : %d(%s) n", getegid(), getgrgid(getegid())->gr_name); } 36

set-user-id 실행파일 l set-user-id 실행권한은 심볼릭 모드로 's'로 표시 $ ls –asl /bin/su /usr/bin/passwd

set-user-id 실행파일 l set-user-id 실행권한은 심볼릭 모드로 's'로 표시 $ ls –asl /bin/su /usr/bin/passwd 32 -rwsr-xr-x. 1 root 32396 2011 -05 -31 01: 50 /bin/su 28 -rwsr-xr-x. 1 root 27000 2010 -08 -22 12: 00 /usr/bin/passwd l set-uid 실행권한 설정 $ chmod 4755 file 1 l set-gid 실행권한 설정 $ chmod 2755 file 1 38