Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C (not C++) program contents of a directory specified as an argument at the command line. that forks a child process and uses

image text in transcribed
Write a C (not C++) program contents of a directory specified as an argument at the command line. that forks a child process and uses one of the exec functions to list the The child process should first display the current working directory and then then attempt to change to the specified directory. It should then execute (using one of the exee functioes) the command Is (with the arguments-all,-1 (lowercase L), and -haman-readable) If the specified directory cant be accessed (e.g, the user doesnt have permission or the directory doesn't exist), an appropriate response should be displayod (see below) In the case of any error, the child process s exit with a retun value of O if the directory listing is saccessful. I the user does not specily a directory at the command line, an appropriate usage message should be displayed. Here is some sample outpur to help clarify hould exit with a return value of1. The child process should /prog2 Usage 3 /prog2 Current working directory: /home/ibrahim Executing ls .all-1human-readable total 24M drwxr-xr-x 74 ibrahin ibrahim 20K Oct 26 16:08 drwxr-xr-x 6 root root 4.OK Apr 10 2014 w---1 ibrahin ibrahim 4.1K Sep 13 12:09.bashrc drwxE-xr-x 7 ibrahin ibrahim 4.0K Oet 11 14:51 Desktop/ snip Exit status: 0 Current working directory: /hone/ibrahim Executing ls /--ll-human-readable total 132K drwxr-xE- 22 root root 4.0K May 25 09:49 drwxr-xr-x 22 root root 4.0K May 25 09:49 drwxE-xE-x2 oot root 4.0K Feb 25 2016 bin/ drwxr-xr-x4 root root 4.OK Feb 25 2016 boot/ snip Exit status: 0 prog2/root ory: /hone/ibrahim Executing ls /root-all -1-human-readable Can't chdir to /root Exit status: 1 op$./prog2 toor/toor/toor y: /hone/ibrahim/Desktop Current working Executing ls /toor/toor/toor--all-1-human-readable Can't chdir to /toor/toor/toor Exit status: 1 A few notes: (1) The parent process must correctly display the exit status of the child (2) The child process must display the current working directory, atempt to change to the specified directory, execute Is with the specified arguments, and either teminate with exit(0) or exit) Hints

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_2

Step: 3

blur-text-image_3

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions