Due Date: August 13, 2017 23:59 hours
The project developed in Lab
#2 and #3 part 1 will be extended by this one. Using stat you will need to open each file within a child process and determine the following: the user ID and the group ID and then compare these to the current user. The 3 cases are: if the user is the owner, the user is in the same group as the owner, or if the owner is outside of the user group. After that information is printed, then print the combination of file permissions that apply to this file: read, write, execute. Sample code: man stat, man 2 stat, man getpwuid,
man readdir, man 3 scandir, and fileaccess.c
Program requirements:
- The program should take either filenames or wildcards (*.c
for example) as input.
- Create as many child processes as there are files on the
command line.
- (you may remove the ps -H) The parent process should wait for all the children to finish and then print “ps -H”
- For each child process:
- Print if you have owner, group, or general permissions. Hint:
getuid(); & getgid();
- For the appropriate type, print what type
of permissions you have: read, write, execute
5. If no filename is specified on the command prompt, use dirent to retrieve all files in the current folder. Modular code will make this task much easier, but is not required.
6. Use the output from stat to determine the owner of the file, and then use the passwd structure on the owner of the file to determine the home directory of the user that owns that file.
- 10% Extra Credit: Your print output may occasionally be garbled. How would you fix this? (Hint: Semaphores implemented as pipes – see below) Separate program operations and print statements as best as possible. Consider the printf statements as a critical section. Do not use delays or wait inside your main loop, or make child processes wait in any way.
- 20% Extra Credit: modify the semaphores to use pthreads instead of the pipe constructs P() & V() that are provided below
- 5% Extra
Credit: instead of Canvas, submit your assignment via https://education.github.com/ (MUST
be private, invite swirsz) I will use Github’s last modified date as the
submission date. Make sure to put your full name in the header of your
file.
(example below)
Last Revised: August 14, 2017