Last active
October 9, 2019 06:14
-
-
Save surinoel/d6bebcd2961bcdc43d9a2be8546517ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 사용자 모드에서 프로그램 실행 */ | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
int main(void) | |
{ | |
int fd; | |
/* | |
1) open 시스템 콜 호출 | |
2) 커널 모드로 전환 | |
3) open 함수를 처리하는 sys_open() 커널 함수 호출 | |
4) 파일 열기 연산 수행 | |
5) 사용자 모드로 전환 | |
6) 이후 프로그램 코드 수행 | |
*/ | |
fd = open("data.txt", O_RDONLY); | |
if(fd == -1) { | |
printf("Error: cannot open file\n"); | |
return -1; | |
} | |
else { | |
printf("File opened and now close\n"); | |
close(fd); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment