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. ±× ¹Û¿¡ ½Ã°£ÀÚ¿ø ¶
|
Let not the sands of time get in your lunch. |