Saturday, January 15, 2011

OS-> STAT SYSTEM CALL


STAT SYSTEM CALL



 AIM:

           To write a c-program to implement stat system call.

 ALGORITHM:

    STEP 1:  Start the program.
    STEP 2:  Include the header file as <sys/stat.h>
    STEP 3:  In main have three arguments such as i,avge,argv.
    STEP 4:  Declare sbuffs as structure variable that structure have stat.
    STEP 5:  To display the filename,node1,user id,group id,mode of the
                    corresponding system.
    STEP 6:  Stop the program.





















PROGRAM:

 #include<stdio.h>
 #include<sys/stat.h>
 main(int i,int avge,char**argv)
  {
    struct stat sbuff;
    if(!stat(argv[i],&sbuff)==-1)
    printf("could not stat file",1);
    printf("\n file name:%s",argv[i]);
    printf("\n inode no:%i",sbuff.st_ino);
    printf("\n user id:%u",sbuff.st_uid);
    printf("\n groupid:%g",sbuff.st_gid);
    printf("\n mode:%f",sbuff.st_mode):
    printf("\n size of flie:%d",sbuff.st_size);
    exit(0);
  }



OUTPUT:

 $ cc stat.c
 $./a.out
 File name: HOSTNAME=net64
 inode no: 0
 User id: 24641422
 Groupid:-1.79259
 Mode:-1.792591
 Size of the file:0