Write a C Program to Implement STAT System Call

Aim:

To write a C Program to Implement STAT System Call.

Description:

stat() is a Unix system call that returns file attributes about an inode. The semantics of stat() vary between operating systems. As an example, Unix command ls uses this system call to retrieve information on files that includes:

  • atime: time of last access (ls -lu)
  • mtime: time of last modification (ls -l)
  • ctime: time of last status change (ls -lc)

Algorithm:

  • Step 1 − START.
  • Step 2 – Use library stat.h
  • Step 3 − Declare the struct stat sfile
  • Step 4 − print the sfile
  • Step 5 − STOP.

Program:

#include<stdio.h>
#include<sys/stat.h>
int main()
{
  struct stat sfile;
  stat("stat.c", &sfile);
  printf("st_mode = %o", sfile.st_mode);
  return 0;
}

Execution:

st_ = 26750123200

Result:

Thus STAT system call program was executed Successfully.

Leave a Comment