Thursday 29 September 2011


IMPLEMENTATION OF LINUX SYSTEM CALL
[stat()]
AIM:

To write a C program to know the status of the file using LINUX system call stat().

ALGORITHM:

Step1: Start the process.
Step2: Define a structure stat.
Step3: Declare two unsigned variables for storing the address and total size of the file
Step4: Specify the filename and check the status of file using stat() system call
Step5: Print the address and size of the file.
Step6: Stop the process.

PROGRAM:

#include<sys/stat.h>
#include<stdio.h>
int main()
{
Struct stat s;
unsigned long a;
unsigned long b;
if(stat(“test.c”,&s)==(-1))
{
perror(“Error:cannot stat file”);
exit(EXIT_FAILURE);
}
a=s.st_blksize;
b=s.st_size;
printf(“%u \t %u \n”,a,b);
return 0;
}

OUTPUT:

gcc stat.c
address:4096                          total size:52

0 comments:

Post a Comment