Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Shell Program - Write, compile, and run a C program for a custom-shell. Part 1.

ID: 3693666 • Letter: S

Question

Shell Program - Write, compile, and run a C program for a custom-shell. Part 1. Command Parsing (and print its components correctly). Your shell should be able to parse the command from user. Assume my home directory is: /home/richard or you may use ~/ Examples (You may create your own output format or template to show the command(s) being parsed.) 1. One command with arguments and options. For example, ls –la /home/richard Command: ls Options: -la Arguments: /home/richard 2. Two commands with 1 pipe. For example, ls –la /home/richard Command: la Options: -la Arguments: /home/richard For example, ls | wc –l should be parsed and display Command: ls Pipe Command: wc –l 3. Two commands with semicolon. For example, ls ; date 4. One command with IO redirection symbol (<, >, >>) For example, ls < junk.txt > output.txt Command: ls File Redirection: < File: junk.txt File Redirection: > File: output.txt 5. Three commands or more commands with pipe (and with other symbols). For example ls –l | grep *.txt | wc –l ls –l | grep *.txt | wc –l | ls > junk.txt Part2. File Redirection. >, <, >> with a single command using fork/exec, dup/dup2, and/or pipe For example, ls > output.txt ls >> output.txt sort < output.txt Part 3. Implement a shell (using fork, pipe, dup/dup2, exec) for a single command (Part 1), two commands, and then multiple commands (1) Handle two commands with fork, pipe, dup/dup2. ls -l | wc -l Given a command from user, it forks a child process to execute the command while parent waits. When it is done, parent process wakes up and prints prompt for next command. Syntax: command [options] | command [options] Test line: ls -sF | wc -l Part 3. (2) Handle multiple-commands with pipe e.g., ls -l | sort | head (3) Handle multiple-commands with pipe, and file redirection e.g., ls -l | sort | head > output.txt e.g., cat < output.txt | grep ".c" | head > list.txt Part4. Send a command via socket program to be run a "ls -l" command, and echo its result back to the sender. Implement a server to listen port (nnnnn) for any incoming ls command to be run and to output its result back to the sender. The client sends a command (e.g., ls –l) to the server and receive the result to be output to the console. You may modify the sample programs in Week13 Activity folder (for echo server/client or time server/client) for your base code to be modified. Warning and Caution. Your server's listening port must be free (not taken by someone else) and pick one between 40000 and 64000. If it is taken, your server should use another port available, to be connected by your client. Do not use any port being used by someone else for server to bind and for client to connect (to someone's server, not yours).

Explanation / Answer

The msgget() function initializes a new message queue:

It can also return the message queue ID (msqid) of the queue corresponding to the key argument. The value passed as the msgflg argument must be an octal integer with settings for the queue's permissions and control flags.

The following code illustrates the msgget() function.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote