You are here : python_2ososfstat

os.fstat() - os

             

The method fstat() returns information about a file associated with the fd. Here is the structure returned by fstat method:


  • st_dev: ID of device containing file

  • st_ino: inode number

  • st_mode: protection

  • st_nlink: number of hard links

  • st_uid: user ID of owner

  • st_gid: group ID of owner

  • st_rdev: device ID (if special file)

  • st_size: total size, in bytes

  • st_blksize: blocksize for filesystem I/O

  • st_blocks: number of blocks allocated

  • st_atime: time of last access

  • st_mtime: time of last modification

  • st_ctime: time of last status change


Syntax


os.fstat(fd)


Example


#!/usr/bin/python

import os, sys

# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Now get  the touple
info = os.fstat(fd)

print "File Info :", info

# Now get uid of the file
print "UID of the file :%d" % info.st_uid

# Now get gid of the file
print "GID of the file :%d" % info.st_gid

# Close opened file
os.close( fd)


Output / Return Value

When we run above program, it produces following result:


File Info : (33261, 3753776L, 103L, 1, 0, 0, 102L, 1238783197, 1238786767, 1238786767) UID of the file :0 GID of the file :0


Limitations


Alternatives / See Also


Reference