About Linux
리눅스에 대하여 ¶
1.1. GNU/Linux 구조 ¶![]() [PNG image (1.87 KB)]
1.2. Linux kernel의 구성요소 ¶![]() [PNG image (1.74 KB)]
1.3. Linux kernel image의 구조 ¶![]() [PNG image (992 Bytes)]
1.4. VFS ¶![]() [PNG image (1.53 KB)]
1.4.1. Loopback 장치 ¶실제 디바이스 장치와 동일하게 동작하도록 하지만 실제로는 하나의 가상장치에 속하는 것을 Loopback 장치라고 합니다.
하나의 파일에 특정 파일시스템의 형식을 갖추어 저장한후 이것을 하나의 장치로 보도록 하여 mount 할수 있는데 이러한 경우 Loopback 파일시스템이라고 합니다. 1.4.2. Ram-disk ¶특별한 저장장치가 아닌 메모리 그 자체를 저장의 용도로 하나의 디스크처럼 사용할수 있도록 해놓은것을 Ram-Disk장치라고 합니다. 이것은 Loopback 장치처럼 특정 파일시스템으로 포맷할수도 있고 mount할수도 있으며 일반 저장장치보다 메모리를 이용하기 때문에 매우 빠른 read/write/search가 가능하다는것이 장점이지만 전원이 꺼지면 그 자료도 날아간다는 점이 단점이라고 할수 있습니다.
부팅시에는 Loopback 장치로 인식하는 Initial ram-disk를 rootfs으로 하여 복잡한 부팅요구조건을 해결하기도 합니다. 1.5. Process간의 통신지원 ¶가) Signal : 정의된 이벤트를 비동기적으로 알리기 위해서 사용합니다.
나) Pipe : VFS inode를 이용한 통신방식입니다. 이는 redirection등에 많이 사용됩니다.
다) Socket : Network통신을 위한 자원입니다. 대부분 BSD socket interface를 통해서 구현됩니다.
라) System V IPC : MessageQueue, Semaphore, Shared memory등이 IPC자원을 통해서 구현됩니다.
1.6. Memory 할당체계 ¶Kernel에서의 memory할당은 Virtual alloc과 Physical alloc이 수반되며 할당함수는 크게 연속적인 물리공간을 확보하기 위한 함수와 그렇지 않아도 되는 함수로 분류될수 있습니다.
1.7. Linux의 부팅절차 ¶
1.8. Shared Library버젼에 따른 호환 ¶Linux에서는 Shared Library가 보통 파일명이 lib<name>-<version>.so<
어떤 실행프로그램 A가 어떤 shared library를 link하였을때 A는 실행할때는 해당 shared library의 soname으로 주어진 파일명을 찾게 됩니다. 그래서 과거에 만들었던 shared library와 구조가 많이 틀어져서 새로운 shared library가 빌드되어도 서로 다른 soname을 부여하여 빌드하여 이 library를 사용하는 프로그램들이 공존할수 있게 합니다. 만약 내가 빌드한 프로그램이 어떤 library를 사용하고 어떤 soname을 이용하는지 알고 싶으면 "ldd"라는 명령어로 이를 확인할수 있습니다. 1.9. Linux 의 directory구조 ¶
1.10. Real Time Linux (RT-Linux)를 위한 Scheduler관련 조작 ¶Linux는 기본적으로 Hard RTOS는 아니며 Soft RTOS를 지원하는 기능을 가지고 있습니다.
아래의 함수들은 CAP_SYS_NICE특권을 가진 User Application에서 호출할수 있는 RealTime OS의 동작을 위한 Scheduler제어함수들입니다. int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); int sched_getscheduler(pid_t pid);
int sched_get_priority_max(int policy); int sched_get_priority_min(int policy);
int sched_setparam(pid_t pid, const struct sched_param *param); int sched_getparam(pid_t pid, struct sched_param *param);
int sched_yield(void);
int sched_setaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask); int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
int nice(int inc); 1.11. Process 관리 ¶전통적인 Unix system에서는 Process를 생성할때 부모Process로부터 자원을 복제하여 새로운 Process를 생성합니다. 그러나 이렇게 자원을 모두 복제하는 경우 자식Process가 모든 자원을 동일하게 모두 활용하는것이 아니고 그 일부분만을 사용하게 되므로 비효율적인 자원소모가 있다가 판단하여 Linux에서는 다음과 같은 해결방안을 사용합니다.
uid_t getuid(void); uid_t geteuid(void); int setuid(uid_t uid); int seteuid(uid_t euid); gid_t getgid(void); gid_t getegid(void); int setgid(gid_t gid); int setegid(gid_t egid); pid_t fork(void); pid_t vfork(void); int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ..., char * const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); void exit(int status); pid_t wait(int *status); pid_t waitpid(pid_t pid, int *status, int options); int system(const char *command); int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); int pthread_join(pthread_t thread, void **retval); int pthread_detach(pthread_t thread);
pid_t pid = vfork();
if(pid == ((pid_t)(-1))) perror("fork");
else if(pid == ((pid_t)0)) { /* 자식 process */
char * const arg[] = { "/bin/ls", "-al", (char *)0 };
(void)execvp(arg[0], arg);
exit(0);
}
else (void)waitpid(pid, (int *)0, 0); /* 부모 process */
1.12. Signal ¶
1.13. File descriptor의 접근 ¶리눅스는 다양한 장치들을 특별한 파일처럼 취급합니다.
int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); int creat(const char *pathname, mode_t mode); int close(int fd); ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count); off_t lseek(int fd, off_t offset, int whence); int fcntl(int fd, int cmd, ... /* arg */ ); int ioctl(int d, int request, ...); int remove(const char *pathname); DIR *opendir(const char *name); int readdir(unsigned int fd, struct old_linux_dirent *dirp, unsigned int count); int closedir(DIR *dirp); int dup(int oldfd); int dup2(int oldfd, int newfd); int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *path, struct stat *buf); int link(const char *oldpath, const char *newpath); int unlink(const char *pathname); int symlink(const char *oldpath, const char *newpath); ssize_t readlink(const char *path, char *buf, size_t bufsiz); int utime(const char *filename, const struct utimbuf *times); int mkdir(const char *pathname, mode_t mode); int rmdir(const char *pathname); 1.14. Inter Process Communication (IPC) ¶
/* pipe */ int pipe(int pipefd[2]); /* stream pipe */ FILE *popen(const char *command, const char *type); int pclose(FILE *stream); /* fifo */ int mkfifo(const char *pathname, mode_t mode); int mknod(const char *pathname, mode_t mode, dev_t dev); /* 세마포어 */ int semget(key_t key, int nsems, int semflg); int semctl(int semid, int semnum, int cmd, ...); int semop(int semid, struct sembuf *sops, unsigned nsops); /* 메시지큐 */ int msgget(key_t key, int msgflg); int msgctl(int msqid, int cmd, struct msqid_ds *buf); int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg); /* 공유메모리 */ int shmget(key_t key, size_t size, int shmflg); void *shmat(int shmid, const void *shmaddr, int shmflg); int shmdt(const void *shmaddr); int shmctl(int shmid, int cmd, struct shmid_ds *buf); 1.15. Linux의 시간 ¶
1.15.1. uptime ¶
1.15.2. System time은? ¶
1.15.3. System clock tick 자원 ¶
#include <sys/time.h>
#include <time.h> #include <unistd.h> typedef unsigned long long __mz_time_stamp_t; #define mz_time_stamp_t __mz_time_stamp_t typedef struct mz_timer_ts { /* need shadow */ long clock_tick; clock_t prev_clock; mz_time_stamp_t time_stamp; }__mz_timer_t; #define mz_timer_t __mz_timer_t static mz_time_stamp_t __mz_timer_time_stamp(mz_timer_t *s_timer) { clock_t s_clock; #if defined(__linux__) /* get linux kernel's jiffes (tick counter) */ s_clock = times((struct tms *)0); #else do { struct tms s_tms; s_clock = times((struct tms *)(&s_tms)); }while(0); #endif if(s_clock == ((clock_t)(-1))) { /* overflow clock timing */ return(s_timer->time_stamp); } if(s_timer->clock_tick <= 0l) { /* get ticks per second */ s_timer->clock_tick = sysconf(_SC_CLK_TCK); if(s_timer->clock_tick <= 0l) { /* invalid clock tick */ return(s_timer->time_stamp); } s_timer->prev_clock = s_clock; } /* update time stamp (clock to upscale) */ s_timer->time_stamp += (((mz_time_stamp_t)(s_clock - s_timer->prev_clock)) * ((mz_time_stamp_t)1000)) / ((mz_time_stamp_t)s_timer->clock_tick); s_timer->prev_clock = s_clock; return(s_timer->time_stamp); } static mz_time_stamp_t mz_get_time_stamp_msec(mz_timer_t *s_timer) { statuc mz_timer_t g_global_timer_local = { 0l, (clock_t)0, (mz_time_stamp_t)1000u }; return(__mz_timer_time_stamp((mz_timer_t *)(&g_global_timer_local)); } 1.15.4. POSIX규격의 clock_gettime 시간자원 ¶
1.15.5. 그 밖에 시간자원 ¶
|
You are going to have a new love affair. |

















![[http]](/imgs/http.png)
)