no image
[System] Socket
Socket은 커널에 구현된 프로토콜 요소의 추상화된 인터페이스 장치 파일의 일종 연결을 끊을 때는 Client가 끊도록 하는 것이 바람직 전체 흐름 Server(서버 소켓 + 통신 소켓) socket() : 소켓 생성 bind() : ip 주소 및 포트를 socket에 묶음(binding) listen() : client로부터의 연결을 대기 accept() : client로부터의 연결 요청에 응답 recv() / send() : 데이터 송수신 Client(통신 소켓) socket() : 소켓 생성 connect() : server로 연결 요청 recv() / send() : 데이터 송수신 API Socket #include #include int socket(int domain, int type, in..
2024.02.02
no image
[System] Semaphore
Process synchronization 다중 프로그래밍 시스템 여러 개의 프로세스들이 존재 프로세스들은 서로 독립적으로 동작 공유 자원 또는 데이터가 있을 때, 문제 발생 가능 동기화 프로세스들이 서로 동작을 맞추는 것 프로세스들이 서로 정보를 공유하는 것 Mutaul exclusion primitives enterCS() Critical section 진입 전 검사 다른 프로세스가 critical section안에 있는지 검사 exitCS() critical section을 벗어날 때의 후처리 과정 critical section을 벗어남을 시스템이 알림 Semaphore 1965년 Dijkstra가 제안 Busy waiting 문제 해결 음이 아닌 정수형 변수(S) 초기화 연산, P(), V()로만..
2024.01.26
no image
[System] Shared Memory
Shared memory 같은 메모리 공간을 프로세스들이 공유 동시에 Read/Write가 가능 Synchronization(동기화 필요) Dynaminc allocation -> fork()인 경우, 공유되지 않고 메모리 영역의 복사본이 생성됨 allocation shared memory segment #include #include int shmget(key_t key, size_t size, int shmflg); key : IPC key IPC_PRIVATE : private shared memory 생성 size : 공유할 메모리 크기(bytes) shmflg : 생성 방법 및 접근 권한 IPC_CREAT : key에 대한 shared memory가 없으면, 생성 IPC_EXCL : key에 대..
2024.01.26
no image
[System] Named Pipe
Named Pipe 이름이 있는 파이프(특수 파일, FIFO파일) 독립적인 프로세스 사이의 통신을 위해 사용 가능 FIFO 파일을 미리 만들어 두어야 함 Kernel 내부적으로 데이터 전달(파일에 내용이 쓰여지진 않음) creating a FIFO file #include #incldue int mkfifo(const char* pathname, mode_t mode); IPC with a named pipe 두 개의 프로세스가 하나의 FIFO 파일을 통해 통신 가능 proc.A : 쓰기 모드로 file open proc.B : 읽기 모드로 file open Example server #include #include #include #include #include #include int main(void..
2024.01.26
no image
[System] 메모리 맵핑
Mapping a file into memory File을 프로세스의 가상 메모리 공간으로 매핑 File I/O system call 사용하지 않고 접근 #include void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset); addr : 매핑할 메모리 주소 hint(일반적으로 NULL사용) length : 매핑할 길이(byte단위) prot : memory protection mode PROT_NONE : 접근할 수 없음 PROT_READ PROT_WRITE PROT_EXEC flags : 매핑 형태와 동작 방식 지정 MAP_FIXED : Mapping 할 주소를 지정 MAP_PRIVATE : 변경된 내용이 공유 ..
2024.01.26
no image
[System] 시그널
시그널 software interrupts 비동기적으로 발생하는 이벤트를 처리하기 위한 매커니즘을 제공 Interrupt 예상되지 않고 외부에서 발생된 이벤트 Interrupt Handling 인터럽트 발생 프로세스 중단(커널에 의해서) 인터럽트 처리 인터럽트 발생 장소, 원인 파악 인터럽트 서비스 할 것인지 결정 인터럽트 서비스 루틴 호출 Life cycle of a signal 발생 프로그램에서 발생한 예외적 상황 ex) divide by zero 사용자의 입력 ex) ctrl+c process 또는 kernel에서 생성/전달 보관 signal 전달 전까지, kernel이 보관 전달 가능해지면, 해당 process에게 전달 처리 지정된 방법에 따라 signal 처리 ignore catch defaul..
2024.01.25
no image
[System] 프로세스 관리
Running a new process Executing a new program : binary program을 읽어서 자신을 호출한 process의 메모리 영역에 덮어 씀(기존 program은 중지) Creating a new process(forking) : 자신을 호출한 process(parent process)를 복사하여, 새로운 process 생성 #include int excl(const char* path, const char* arg, ... /* (char*) NULL */); int exclp(const char* file, const char* arg, ... /* (char*) NULL */); int exele(const char* path, const char* arg, .....
2024.01.25
no image
[System] 프로세스
Program vs Process 프로그램 : 실행할 프로그램 + 데이터, 컴퓨터 시스템에 실행 요청 전의 상태 프로세스 : Running program, 실행을 위해 시스템(커널)에 등록된 작업, 시스템 성능 향상을 위해 커널에 의해 관리됨 Process ID(PID) Process에 부여된 식별 번호(유일성) Parent process : 자신을 생성한 프로세스, 모든 프로세스는 부모 프로세스가 있음 parent process id(ppid) getting pid / ppid #include #include pid_t getpid(void); pid_t getppid(void); Process group 관련된 process들을 묶은 것 ex) shell script 내부의 명령어들 하나의 job 수..
2024.01.25
no image
[System] 시스템 정보
Linux/Unix system information 시스템에 설치된 OS에 관한 정보 호스트명 정보(컴퓨터 이름) 하드웨어 종류에 관한 정보 하드웨어에 따라 사용할 수 있는 자원의 최댓값 최대 프로세스 개수 프로세스 당 열 수 있는 최대 파일 개수 메모리 페이지 크기 등 getting system info #include int uname(struct utsname* buf); return 0 : success -1 : error #include int sysinfo(struct sysinfo* info); return 0 : success -1 : error getting resource info #include long sysconf(int name); name : 검색할 정보를 지징하는 상수(ma..
2024.01.24