Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ language please: use the manual pages for the proper use of the execv() function. Need to #include the header file to use this function.

c++ language please: use the manual pages for the proper use of the execv() function. Need to #include the header file to use this function. execv() allows a process to change its program. Uusually done by a child process soon after being forked() by its parent. You can think of the typical Linux shell as a parent process that forks() a child for each command a user enters.

write a shell, can be Relaxed Shell. Here are the characteristics of Relax Shells operations:

1) You will present the user with the Relaxed prompt: Relax>

2) The user will enter the full path of a command along with any arguments for that command as one string. An example might be:

Relax> /bin/ls l

Here, the user has entered the string /bin/ls l at the prompt.

3) You will tokenize the users input into a NULL-terminated array of char strings, say cmd_args, such that

cmd_args[0] = /bin/ls

cmd_args[1] = -l

cmd_args[2] = NULL

4) You will fork() a child process

5) The child will invoke the execv() function to execute the users command (in argv[0]) and also pass the cmd_args[] array to execv().

6) The parent will wait for the child to exit (see section 2 of the manual pages for use of the waitpid() function.)

7) If the childs execv() call returns an error, the child should exit. For 10 points of extra credit, have the child return the error number to the parent. The parent should print this to the screen.

8) The parent repeats from step 1

Note that because the shell does not follow the execution path, the user must enter the complete path for the command she wishes to execute. Most Unix commands are either found in /bin or /usr/bin. Use the which command from a standard shell prompt to determine the location of specific commands.

Tips:

  • Start simple. Begin by creating a simple program that simply forks a child process. Verify that a string variable assigned in the parent prior to the fork() is accessible in the child by having the child print out the string.

  • Next, attempt to have the child change its program by hardcoding the path to an executable like /bin/ls directly into the execv() function. Use an empty argument list for this test.

  • Next, verify that you can get the parent to wait for the child to complete. To do this, have the child run a process like /usr/bin/top or /usr/bin/nano that will run until the user quits. Have the parent print out a goodbye message only after the child quits.

  • Work on the tokenization of the string passed from the parent to the child

  • Add error trapping: you should report an error if either the parents fork() or the childs execv() call fails.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions