Answered You can hire a professional tutor to get the answer.

QUESTION

Operating System-C language - Implement ls function with -lLR Write a program that behaves exactly like the Unix command ls -lLR . The C program...

Operating System-C language - Implement ls function with -lLR

Write a program that behaves exactly like the Unix command ls -lLR.  The C program should be submitted as a source file called myls.c, with a Makefile called Makefile_myls that outputs a binary file called myls.  You will want to use the stat system call from C and you will need to determine how to recurse into directories.  Test your program by running ls itself (you MUST give the full ls path /bin/ls or your .bash_aliases may add some extra command switches you don’t want!):

$ /bin/ls -lLR /var/www > out1.txt

$ ./myls /var/www > out2.txt

$ diff out1.txt out2.txt

The third line shouldn’t print anything if myls is done correctly.  Please make sure your program exhibits this exact behavior on the openlab machines!

Hint: look up the stat API

Note: ls prints results in alphabetical order of file names, starting with the topmost directory and then recursing in a depth-first manner.  Note however, that it does this alphabetical sorting by first sorting based on the file name, and THEN the extension if there’s a tie.  If you do ls /var/www/icons/small on openlab, you’ll see this reflected in the following ordering:

generic2.gif

generic2.png

generic.gif

generic.png

If there is no file extension, the file should be sorted as before an identical name with an extension (e.g. “generic” should show before “generic.gif”)

Note: the time last modified printed by ls will display a time of day if in the current year or the year if not.  For some directories with an SELinux context, this appears to not always be true (probably due to some security feature).  Don’t worry about this case: assume that you should print the time of day unless the year is a previous year, in which case you should print the year instead.

Note: you may notice that some files have a ‘.’ that appears after the mode bits.  This is associated with an SELinux security context.  Don’t worry about this case: the test directory hierarchy for your program will not include any such files so you can safely ignore them.

Note: although ls can accept multiple file arguments, we will only test you on one argument.  Remember, though, that the default value of this arg is . (current directory)!

Note: Do not just use a system shell call to execute ls -lLR from your program.  This will earn you a 0!

Note: Do not worry about symlinks or devices.  Assume that all arguments will be regular files or directories.  Note that the -L argument means to resolve symlinks for files within these directories and display information for the file they point to.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question