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
no image
[System] Files in Unix/Linux
Types of files regular file : 텍스트 또는 이전 데이터 파일 directory : 파일의 목록을 저장한 파일 symbolic link file : 이미 존재하는 파일이나 디렉토리에 접근할 수 있는 새로운 이름 special file : 장치와 데이터를 주고 받는 통로(장치 번호를 inode에 저장) character device file : character 단위로 데이터 전송 block device file : block 단위로 데이터 전송 File organization file name(hard link) : 사용자가 파일에 접근할 때 사용 inode 파일에 대한 정보를 저장 번호를 통해 관리/접근 ls -i : inode번호 확인 data block : 실제 데이터가 저장된..
2024.01.24
no image
[System] High-Level File I/O
High-Level File I/O(Buffered I/O) C Standard library를 사용해서 파일 입출력 수행 File pointer 사용(ex. File* fp) 버퍼 단위로 디스크에 입출력 ※ 매 byte 마다 disk에 접근해서 write 하는 것은 비용이 큼 -> 메모리의 buffer에 데이터를 저장해서 한번에 disk에 접근 Physical disk address Sector(물리적 데이터 전송 단위)를 지정 Logical disk address Disk System의 데이터 전체를 block들의 나열로 취급 Block 번호 -> physical address 변환 모듈 필요 (disk driver) Disk address mapping OS(kernel) ----> Disk dri..
2024.01.24
no image
[System] Low-Level File I/O
Low-Level File I/O(System call) System call을 이용해서 파일 입출력 수행 File descriptor 사용 Byte 단위로 디스크에 입출력 특수 파일에 대한 입출력 가능 open #include #include #include int open(const char* pathname, int flags [, mode_t mode]); pathname (file path) : 열려는 파일의 경로 flags (file state flags) : 여는 방법(access mode) 설정 mode(file access permission) : 새로 생성(O_CREATE) 할 때만 유효 return : file descriptor File descriptor 열려 있는 파일을 구분하는..
2024.01.23
no image
[C] Makefile & CMake
Makefile Compile 방법을 기술하는 파일 다수의 파일을 한번에 컴파일 가능 Make 주어진 Makefile에 따라 compile을 수행하고 실행파일을 생성 최초 컴파일 이후에는, 변경이 있는 파일만 컴파일 함 Rule Block : Target : Build 대상 이름, 일반적으로 최종 결과 파일명 사용 Dependency : Build 대상이 의존하는 Target이나 파일 목록 Recipe : Build 대상을 생성하는 명령어 app.out: main.o foo.o bar.o gcc -o app.out main.o foo.o bar.o main.o: foo.h bar.h main.c gcc -c -o main.o main.c foo.o: foo.h foo.c gcc -c -o foo.o fo..
2024.01.23