Beginning Linux 4 e 4 int mainint argc
Beginning Linux 4 e 4장 리눅스 환경
프로그램 인수 • int main(int argc, char* argv[]) – argc : 인수 개수 – argv : 프로그램 이름(argv[0]) 부터 인수 문자 열 – 보통은 Shell에 의해 제공됨. – Linux shell은 와일드카드 확장을 수행 • Ex) myprog left right ‘and center’ – Command Console : “myprog” ”left” ”right” “and” ”center’” – Linux : “myprog” ”left” ”right” ”and center”
getopt_long – int getopt_long(int argc, char *const argv[], const *optstring, const struct option *longopts, int *longindex); – #define _GNU_SOURCE 반드시 필요 – 앞의 3개의 매개변수는 getopt와 동일 – struct option *longopts: 긴 옵션 구조체 배열 – int longindex : longopts와 관련된 index값
시간과 날짜 • struct tm *gmtime(const time_t *timeval); – 저수준 시간 값을 tm 구조체로 리턴 – GMT기준 • struct tm *localtime(const time_t *timeval) – 지역 시간대와 summer time 설정을 반영 • time_t mktime(struct tm *timeptr); – 구조체를 저수준 값으로 변환. 안되면 -1
시간과 날짜 • #include<time. h> • char *asctime(const struct tm *timeptr); • char *ctime(const time_t *timeval); – 사용자에게 익숙해 보이는 문자열 리턴 – Sun Jun 9 12: 34: 56 2007n
시간과 날짜 • size_t strftime(char *s, size_t maxsize, const char *format, struct tm *timeptr); – timeptr 구조체를 format형식에 맞추어 s에 저 장한다. – maxsize : s는 maxsize개의 문자를 담을 수 있 어야 함. • char *strptime(const char *buf, const char* format, struct tm *timeptr); – Buf를 format 형식에 맞추어 timeptr에 저장. – 리턴은 함수 실행 후 문자 포인터 위치
로깅 – #include <syslog. h> – void syslog(int priority, const char *message, arguments…); • 우선순위 수준값 : 내림차순 정의 – LOG_EMERG : 긴급 – LOG_ALERT > LOG_CRIT(하드웨어 실패) – LOG_ERR – LOG_WARNING>LOG_NOTICE>LOG_INFO – LOG_DEBUG
자원 한계 관련 함수 • int resource 매개변수 – RLIMIT_CORE : core dump 파일 크기 한계 – RLIMIT_CPU : CPU 시간 한계(초단위) – RLIMIT_DATA : data segment 크기 한계(byte) – RLIMIT_FSIZE : 파일 크기 한계(byte) – RLIMIT_NOFILE : 열린 파일 개수 한계 – RLIMIT_STACK : 스택 크기 한계(byte) – RLIMIT_AS : 주소공간(stack) 한계(byte)
- Slides: 38