Computers/Linux System Programming 16

ch13. Daemon process

*_* ★ --- 수업시간엔 독립형 디몬만! [디몬 코딩 수칙] 1) umask 호출 ---- 파일 모드 생성 마스크를 0 으로 설정 2) fork 호출 뒤, 부모 프로세스 종료(exit) 3) setsid 호출하여 새로운 세션 생성 4) (opt) 현재 작업 디렉토리를 루트로 변경 5) 필요하지 않은 파일 디스크립터 전부 close 6) 표준입출력,오류 출력의 라이브러리 루틴을 무효화 ~ /dev/null 에 대해 오픈 7) SIGHUP 무시 void daemonize(const char *cmd) { int i, fd0, fd1, fd2; pid_t pid; struct rlimit rl; struct sigaction sa; /* * Clear file creation mask. */ umask(0..

ch11. Threads

[스레드 식별] ◆ pthread_equal#include pthread_equal(pthread_t tid1, pthread_t tid2);(ret) 둘이 같으면 0 이 아닌값, 같지 않으면 0 ◆ pthrerad_self#include int pthread_self(void);(ret) 호출한 스레드의 스레드 아이디 [스레드 생성] ◆ pthread_create#include pthread_create(pthread_t *restrict tidp, const pthread_attr_t *restrict attr,void *(*start_rtn)(void*), void *restrict arg);(ret) success : 0 failed : 오류번호 (ㅇㅖ) err = pthread_create(&n..

+ ch9. ( addition) process relationship

- process : 4가지의 사용자 ID : real, effective, saved, file owner [ 실제 사용자 아이디 : real user id (ruid) ] - 프로세스를 실행한 원래 사용자의 id - 사용자 id는 프로세스 부모의 실제 사용자 id로 설정되며, exec 호출 도중에 변경되지 않는다. - 대개, login 프로세스는 login shell의 실제 사용자 아이디를 해당 사용자의 실제 사용자 id로 설정한다. - 특권 사용자(root, superuser)는 실제 사용자 id를 다른 값으로 변경할 수 있지만, 다른 사용자는 변경불가 [ 유효 사용자 아이디 : effective user id(euid) ] - 프로세스가 영향을 미치는 사용자 id - 접근 권한의 기준으로 사용 -..

ch9. process relationship

[프로세스 그룹] ◆ getpgrp : 현재 프로세스의 프로세스 그룹 ID 값을 돌려줌#include pid_t getpgid(void); (ret) success : 호출한 프로세스의 프로세스 그룹 ID ◆ getpgid : 프로세스 id를 인자로 받아 그 플세스가 속해이는 프로세스의 그룹 id를 돌려줌#include pid_t getpgid(pid_t pid); (ret) success : 성공시 프로세스 그룹 id failed : -1 ◆ setpgid : 프로세스가 자신의 기존의 프로세스 그룹에 속하게 하거나 새 프로세스 그룹을 생성#include int setpgid(pid_t pid); (ret) success : 0 failed : -1 [세션]◆ setsid : 한 프로세스가 새로운 세션을..

ch8. process control

◆ getpid #include pid_t getpid(void); (ret) 호출된 프로세스의 프로세스 id ◆ getppid #include pid_t getppid(void); (ret) 호출된 프로세스의 부모 프로세스 id ◆ getuid #include uid_t getuid(void); (ret) 호출된 프로세스의 실제 사용자 id ◆ geteuid #include uid_t geteuid(void); (ret) 호출된 프로세스의 유효 사용자 id ◆ getgid #include gid_t getgid(void); (ret) 호출된 프로세스의 실제 그룹 id ◆ getegid #include gid_t getegid(void); (ret) 호출된 프로세스의 유효 그룹 id ◆ fork #inc..

ch6. system data file and system information

//passwd ◆ getpwuid #include struct passwd* getpwuid(uid_t uid); (ret) success : 포인터 failed : NULL ◆ getpwnam #include struct passwd* getpwnam(const char *name); (ret) success : 포인터 failed : NULL ◆ getpwent #include struct passwd* getpwent(void); (ret) success : 포인터, 파일 끝이면 NULL failed : NULL ◆ setpwent #include void setpwent(void); ◆ endpwent #include void endpwent(void); #include #include #inc..

ch5. standard I/O library

◆ fwide #include #include int fwide(FILE *fp, int mode); (ret) 스트림이 넓은 문자 지향이면 양수, 바이트 지향이면 음수, 지향이 없으면 0 ◆ setbuf #include void setbuf(FILE *restrict fp, char *restrict buf); (ret) success : 0 failed : 0이 아닌 값 ◆ setvbuf #include int setvbuf(FILE *restrict fp, char *restrict buf, int mode, size_t size); (ret) success : 0 failed : 0이 아닌 값 ◆ fflush #include int fflush(FILE *fp); (ret) success : 0 ..