[Linux System Programming 1] [Linux System Programming 2] [Linux System Programming 3] [Linux System Programming 4] [Linux System Programming 5] ==== 4일차 ==== '''ls''' {{{ls [옵션]}}} ||옵션||기능|| ||-a, --all||디렉토리 내의 모든 파일 출력|| ||-l, --format=long ||파일정보(파일종류, 퍼미션, 사이즈)를 표시 || ||-s, --size ||1K 블록 단위로 파일 크기 표시 || ||-t, --sort=time ||최근의 파일부터 출력 || ||-c, --time ||파일 최근 변경 시간에 따라 정렬해서 출력 || ||--color ||파일 종류에 따라 색상 표시 || ||-R(recursive) ||현재 작업 디렉토리와 하위 디렉토리 모두 출력 || ||--help ||도움말 || '''useradd''' useradd -d /home/nanbean -p 111 ooo ( 유저를 생성한다. ) '''chmod''' chmod u+x test ( 유저에 s 권한을 주겠다. ) '''chown''' chown 775 /home/sample/test ( test파일에 775를 준다. ) '''su''' su -l ( 다른계정으로 넘어가는데 완전한 권한(-l)을 가져온다. ) ---- {{{#!geshi c #include #include #include #include #include int main(int argc, char *argv[]) { struct stat st ; if(stat(argv[1], &st ) == -1) { perror("[ Stat Error ]\n") ; exit(1); } printf("[ Dev : %d ]\n", st.st_dev) ; printf("[ rDev: %d ]\n", st.st_rdev) ; printf("[ Size : %d ]\t YUD:%d ]\t[GID:%d ]\n", st.st_size, st.st_uid, st.st_gid) ; printf("[ Ino : %d ]\t Mode:%d ]\t[Link:%d ]\n", st.st_ino, st.st_uid, st.st_nlink) ; printf("[ BlkSize: %d ]\t[ BlkNum:%d ]\n", st.st_blksize, st.st_blocks) ; printf("MTime: %s", ctime(&st.st_mtime) ) ; printf("CTime: %s", ctime(&st.st_ctime) ) ; printf("ATime: %s", ctime(&st.st_atime) ) ; } }}} ---- exit(0)의 의미는? 부모 프로세스가 자식 프로세스가 왜 죽었는지 알기 위해서 던져준다. {{{#!geshi c #include #include #include void exit_handler1(void) { printf("[ Arminia-209 ]\n"); } void exit_handler2(void) { printf("[ GL-209 ]\n"); } int main(int argc, char *argv[]) { int num = 0; (argc == 2) ? (num = argv[1][0] - '0') : (exit(0)); if(num!=1) num = 0; printf("[ Ellias-404 ]\n"); atexit(exit_handler2) ; atexit(exit_handler1) ; printf("[ Dellias-404 ]\n"); (num == 0) ? exit(0) : _exit(0) ; } }}} ---- cmos --> start arch/i386/boot/setup.s --> startup_32 arch/i386/kernel/head.s --> start_kernel init/main.c --> init --> login --> 쉘 {{{#!geshi c int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) { long retval, d0; __asm__ __volatile__( "movl %%esp,%%esi\n\t" "int $0x80\n\t" /* Linux/i386 system call */ "cmpl %%esp,%%esi\n\t" /* child or parent? */ "je 1f\n\t" /* parent - jump */ /* Load the argument into eax, and push it. That way, it does * not matter whether the called function is compiled with * -mregparm or not. */ "movl %4,%%eax\n\t" "pushl %%eax\n\t" "call *%5\n\t" /* call fn */ "movl %3,%0\n\t" /* exit */ "int $0x80\n" "1:\t" :"=&a" (retval), "=&S" (d0) :"" (__NR_clone), "i" (__NR_exit), "r" (arg), "r" (fn), "b" (flags | CLONE_VM) : "memory"); return retval; } }}} ---- {{{#!geshi c #include #include #include int main() { pid_t pid; printf("[ Processs PID:%d PPID:%d ]\n\n", getpid(), getppid()) ; switch(pid=fork()) { case -1: perror("[ Fork Error ]\n") ; exit(0); case 0: printf("[ Child PID:%d PPID:%d ]\n", getpid(), getppid()); printf("[ Child END ]\n"); break; default: printf("[ Parent PID:%d PPID:%d ]\n", getpid(), getppid() ); printf("[ Parent END ]\n"); break; } printf("[ Process End : %d ]\n\n", getpid() ); exit(0); } }}} fork()가 실행되면 child 프로세스를 생성해서 수행하고 parent 프로세스를 수행한다. switch 이후의 코드는 child에서도 실행, parent에서도 수행된다. fork()가 수행된 후 parent에게는 child의 PID를 넘겨주고, child에게는 0를 넘겨준다. 그러므로, {{{ [ Processs PID:1839 PPID:1087 ] [ Child PID:1840 PPID:1839 ] [ Child END ] [ Process End : 1840 ] [ Processs PID:1839 PPID:1087 ] [ Parent PID:1839 PPID:1087 ] [ Parent END ] [ Process End : 1839 ] }}}의 결과가 나오게 된다. ---- '''Paging 기법''' 4Gbyte를 공유하고 있다가, 변경될 경우 새로운 메모리를 할당 받는다고 보면 된다.