Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C/shell programming Task 2: Printing the time that the file path was created (50 points) The stat system call can access a file by name

C/shell programming
image text in transcribed
Task 2: Printing the time that the file path was created (50 points) The stat system call can access a file by name and retrieve file status information. It is given by: int stat (const char pathname, struct stat buf) This system call returns a stat structure (both the function and struct are called stat), which contains the following fields struct stat t st_devID of device containing file ino t st ino;/inode number mode_t st_mode; / protection t st nlink; / number of hard links/ t st uid * user ID of owncr/ gid t st gidgroup ID of owner t st rdev;device ID (if special file) t st size; total size, in bytes t st blksize; blocksize for file system LO blkcnt t st blocks; / number of 512B blocks allocated c t st atime; time of last access time t st mtime; time of last modification/ time t st ctime; time of last status change On success, zero is returned. On error, is retuned, and errno is set appropriately. The following program displays the time that the file path was last accessed. Type in and complete the following program on the computer. Save t as printaccess.c. Compile the program, then execute it by giving it a path name as an argument. rintaccess.c: #i #include include sys/stat.h> int main (int argc, char *argv) nclude f define an instance of struct stat (don't use a pointer). Use the stat function store the status of the file in your stat struct stat takes a pointer, so pass your struct by reference with & if /i use perror to print error message then exit program print the last access time for the file using defined instance of Il struct stat. ctime printf ("%s last accessed at %s", argv[1]. ctime(&_statime)); requires a pointer, hence the & below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago