일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- Parenthesis
- 1874
- c
- QA
- LJESNJAK
- 해바
- 전자책
- File 조작
- Zero That Out
- Baekjoon
- 4949
- IT
- c++
- 균형잡힌 세상
- 10773
- 시프
- 입력 버퍼
- system programming
- Process Communication
- BAKA
- 브런치
- 2941
- 바샤
- file IO
- 시스템 프로그래밍
- The Balance of the World
- For Beginners
- 5622
- process control
- 백준
- Today
- Total
목록System Programming (15)
해바
시스템 호출 getenv, setenv 등을 사용하여 환경 변수 PATH의 현재 값을 지우고 Lab #7이 저장된 directory 값으로 변경하는 프로그램을 작성하라. // env.c #include #include #include #include #include int main(int argc, char* argv[]) { char* path, *cwd; if(argc != 2) { printf("usage: a.out \n"); exit(1); } if((path = getenv(argv[1])) == NULL) { printf("File does not exist.\n"); exit(1); } printf("BEFORE ENV : %s\n", path); cwd = getcwd(NULL, BUFS..

다음과 같은 프로그램을 작성하라 : 인자로서 디렉토리 이름과 파일의 접미사(suffix)를 읽어 들인다. 주어진 디렉토리를 탐색하여 이름에 인자로 주어진 접미사가 포함된 첫번째 파일을 찾아 그 파일의 i-node 값과 파일 이름을 출력한다. 주어진 파일이름(*s1)이 접미사 (*s2)를 포함하는지 check 해 주는 함수 int match(char* s1, char* s2)를 활용할 것 int match(char* s1, char* s2) { int diff = strlen(s1) - strlen(s2); if(strlen(s1) > strlen(s2)) return (strcmp(&s1[diff], s2) == 0); else return 0; } #include #include #include #in..
link()와 unlink 시스템 호출을 사용하여 파일의 이름을 바꾸는 Linux의 mv 커맨드를 구현할 것 자기 홈 디렉토리에 lab5 디렉토리를 만든 후 프로그램 파일(mv.c)을 보관할 것 #include #include #include int main(int argc, char* argv[]) { link(argv[1], argv[2]); unlink(argv[1]); close(*argv[1]); return 0; } 컴파일 : %gcc mv.c -o mv.out 실행 : %./mv.out afile bfile
커맨드 라인에서 아래와 같은 내용을 입력받는다 : % ./a.out access() 시스템 호출을 이용하여, 만약 파일이 존재하면 파일에서 20-byte의 데이터를 읽어서 std-out에 출력한다. 만약 존재하지 않으면 파일을 새로 만들어, "hello world"라는 내용을 파일에 write 한다. 자기 홈 디렉토리에 lab4 디렉토리를 만든 후 프로그램 파일(access.c)을 보관할 것 #include #include #include #include #include #include #include #define SIZE 20 int main(int argc, char* argv[]) { int fd; if(argc != 2) printf("usage : a.out "); if(access(argv[..
stat() 시스템 호출을 이용하여 파일의 정보를 출력한다 : 주어진 하나의 파일의 inode 번호를 출력한다. 해당 파일의 처음 생성 날짜/시간, 마지막으로 업데이트 된 날짜/시간, 마지막으로 접근한 날짜/시간을 출력한다. 자기 홈 디렉토리에 lab3 디렉토리를 만든 후 프로그램 파일(stat.c)을 보관할 것 #include #include #include #include int main() { int fd; struct stat sb; if(stat("testfile", &sb) == -1) { perror("stat"); return 1; } printf("Inode number : %ld\n", (long)sb.st_ino); printf("처음 생성 날짜/시간 : %s", ctime(&sb.s..
lseek() 시스템 호출을 사용하여, 파일의 원하는 부분을 출력하도록 만든다 : 테스트용 입력파일 "test.txt"에 "abcdefghijklmnop"를 저장한다. lseek 를 사용하여 파일의 시작에서 10개의 character를 건너뛴 후 부터의 내용을 출력한다. lseek 를 사용하여 파일의 끝에서 앞쪽으로 5개의 character를 건너뛴 후 그 내용을 출력한다. 자기 홈 디렉토리에 lab2 디렉토리를 만든 후 프로그램 파일 size.c를 보관할 것 #include #include #include #include #include #include #define BUFSIZE 512 int main() { int fd; char buf1[BUFSIZE] = ""; char buf2[BUFSIZE]..
open(), close(), read(), write() 시스템 호출을 이용하여, 한 파일의 내용을 다른 파일에 복사하는 copy.c 프로그램을 작성하라. #include #include #include #include #define BUFSIZE 512 #define PERMS 0644 int main(int argc, char** argv) { char buffer[BUFSIZE]; int ofd, nfd;// ofd : 원본파일, nfd : 생성할 파일 ssize_t nread; if((ofd = open(argv[1], O_RDONLY)) == -1) { printf("Cannot open %s\n", argv[1]); exit(1); } // 원본파일 열기 if((nfd = open(argv[..