해바

Lab #3 본문

System Programming

Lab #3

Bacha 2019. 11. 16. 21:20

stat() 시스템 호출을 이용하여 파일의 정보를 출력한다 :

  • 주어진 하나의 파일의 inode 번호를 출력한다.
  • 해당 파일의 처음 생성 날짜/시간, 마지막으로 업데이트 된 날짜/시간, 마지막으로 접근한 날짜/시간을 출력한다.
  • 자기 홈 디렉토리에 lab3 디렉토리를 만든 후 프로그램 파일(stat.c)을 보관할 것

 

 

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <time.h>

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.st_ctime));
    printf("마지막으로 업데이트 된 날짜/시간 : %s", ctime(&sb.st_mtime));
    printf("마지막으로 접근한 날짜/시간 : %s", ctime(&sb.st_atime));

    return 0;
}

 

 

컴파일 :

%gcc stat.c

 

 

실행 :

%./a.out

'System Programming' 카테고리의 다른 글

Lab #6  (0) 2019.11.16
Lab #5  (0) 2019.11.16
Lab #4  (0) 2019.11.16
Lab #2  (0) 2019.11.16
Lab #1  (0) 2019.11.16
Comments