File Table in Operating System In-kernel per-process list of open files → process의 PCB에 존재하는 open file table입니다. 즉, process마다 존재하는 file table입니다.Indexed via nonnegative integers known as file descriptors (fds) → file table의 index로 fd가 표현되기 때문에 음수가 아닌 정수로 표현됩니다.Each entry in the list contains information an open fileinodeFile offset → 파일 내부에 존재하는 I/O 작업의 pointerAccess modes → 접근 권한 File descripto..
[학교 수업]/[학교 수업] 시스템 프로그래밍
Dining-Philosophers Problem Philosophers who spend their lives thinking and eatingWhen a philosopher thinks, he/she does not interact with his/her colleaguesWhen a philosopher get hungry, he/she tries to pick up the two chopsticks that are closest to him/herChopsticks that are between him/her left and right neighborsHe/she cannot pick up a chopstick that is already in the hand of a neighborWhen ..
Data Sharing volatile int ncount;void* do_loop(void *loop){ while(1) ncount++; return NULL;}int main(int argc, char *argv[]){ int status, sec; pthread_t thread_id; ncount = 0; sec = atoi(argv[1]); status = pthread_create(&thread_id, NULL, do_loop, NULL); if (status != 0){ perror("pthread_create"); exit(1); } sleep(sec); pthread_cancel(t..
Operating System ThreadsExecution units in a process → 서로 다른 threads는 같은 address space를 공유한다. 같은 process에서의 실행 유닛이기 때문이다.Each thread runs in the context of the process and shares the same code and global data Easier to share data between multiple threads than processes → fork()를 통해 multi-process를 하는 것 보다는 multi-tread를 하는 것이 더 쉽고 빠르다.Typically, more efficient than processes Virtual Address Space ..
SysV: Message Queue Message Formatstruct msgbuf { long mtype; /* type of message */ char mtext[N]; /* message text */} Can be thought of as a template for message datamtype is mandatory and must be a positive numbermtext is not restricted to holding only arrays of characters, but any data, in any formMessage Format은 보내고싶은 메시지의 템플릿이라고 볼 수 있습니다. SysV의 Message Queue에 들어가는 Message는 구조체로 만들어..
Create int pipe(int pipefd[2]);int pipe(int pipefd[2], int flags);creates a pipe, a unidirectional data channeldata written to the write end of the pipe is buffered by the kernel until it is read from the read end of the pipepipefd[] is used to return two file descriptors referring to the ends of the pipepipefd[0]: read endpipefd[1]: write endpipe()의 인자로 int타입 배열을 넣어주면 r/w ends을 return해준다.flagsO..
Signals A very simple way of sending messages between two proecesses → Information transferred is limited to a signal number (standard signal)시그널은 프로세스간의 메시지를 주고 받는 가장 간단한 방법이지만, 그 정보가 시그널 숫자로 제한된다는 한계를 갖는다. Inter-Process Communication (IPC) Pipe → Stream oriented (e.g., TCP) → Data가 쌓이면 그냥 뭉쳐버린다.Message queue → Message oriented (e.g., UDP) → Data가 오면, 덩어리 (메시지) 단위로 쌓는다.Shared Memory → A virtual..
POSIX Signals Standard SignalsQueueing and delivery semantics for standard signalsIf multiple standard signals are pending for a process, the order in which the signals are delivered is unspecifiedStandard signals do not queue → 시그널은 저장되지 않고, 그냥 도착했다는 사실밖에 알 수 없다.e.g., signal(), kill() Real-Time SignalsSIGRTMIN ~ SIGRTMAXSupport at least _POSIX_RTSIG_MAX (8) real-time signals → 적어도 8개의 RT signal..