Question: I need it asap please help me 2 Task To complete this assignment, you have to write a C program that would serve as an

I need it asap please help me

I need it asap please help me 2 Task To complete this

2 Task To complete this assignment, you have to write a C program that would serve as an enhanced" terminal. It has several components that should be approached in step by step fashion to simplify the learning process. The items your program should be able to do: 1. First of all, your program should terminate when it reads "stop" com- mand, otherwise expecting for a command in an infinite loop. (Note, it should perform a clean exit) 2. Second feature of your program, upon reading the onechild command, your shell should be able to spawn a child process and report parent and child addresses. Hint: fork().getpid() and getppid() can be used for that 3. Thirdly, upon receiving "addnumbers" command, your program should be able to sum the mumbers from consecutive input, until a zero is typed in. This should be done by setting up two pipes, forking a process, and in parent process start receiving the inputs, sending them to the child process. Child process should be reading from the pipe until zero is en countered storing the sum into a temporary variable. After zero is read, the child process should send the total sum to the parent process and parent process should output the result. 4. Fourth item to complete is: Upon reading "exec" input into the com- mand line, your program should read arguments until an ";" is encoun- tered. After that, the command should be executed. To do this, your process should read the commands into an array of char* (up to five ar- guments). Further, your process should call the fork syscall, the parent should wait(NULL) for the child process, which in turn should exe- cute the command using either of execvp0), exec(), exec(), execlp) syscall. Note, make sure you initialize your buffer strings to NULL explic- itly as well as allocate and deallocate memory appropriately, 5. Final item is to extend your code from subtask number two, such that upon entering processtree # MAXIMUM DEPTH IS 5 a process tree should be printed. Each process in the tree should report its pid, parent's 2 pid and generation (i.e. the child of the first parent will belong to the first generation, it's children will belong to the second generation etc.). Another important aspect, cach process should be tabulated as many times as there are generations from the parent process. You should use a for loop for spawning the processes, and a variable as the generation counter. To achieve similar output, the parent branch after calling fork() should only wait for the children. Hint: Chapter 3 actually provides a lot of code that can be retised. Hint: To display output right away, you can tise fflush(stdout). 3 Input/Output format For this assignment, you don't have to make sure that input/output redirection works. Please refer to sample execution.txt and sample execution 2.txt. 2 Task To complete this assignment, you have to write a C program that would serve as an enhanced" terminal. It has several components that should be approached in step by step fashion to simplify the learning process. The items your program should be able to do: 1. First of all, your program should terminate when it reads "stop" com- mand, otherwise expecting for a command in an infinite loop. (Note, it should perform a clean exit) 2. Second feature of your program, upon reading the onechild command, your shell should be able to spawn a child process and report parent and child addresses. Hint: fork().getpid() and getppid() can be used for that 3. Thirdly, upon receiving "addnumbers" command, your program should be able to sum the mumbers from consecutive input, until a zero is typed in. This should be done by setting up two pipes, forking a process, and in parent process start receiving the inputs, sending them to the child process. Child process should be reading from the pipe until zero is en countered storing the sum into a temporary variable. After zero is read, the child process should send the total sum to the parent process and parent process should output the result. 4. Fourth item to complete is: Upon reading "exec" input into the com- mand line, your program should read arguments until an ";" is encoun- tered. After that, the command should be executed. To do this, your process should read the commands into an array of char* (up to five ar- guments). Further, your process should call the fork syscall, the parent should wait(NULL) for the child process, which in turn should exe- cute the command using either of execvp0), exec(), exec(), execlp) syscall. Note, make sure you initialize your buffer strings to NULL explic- itly as well as allocate and deallocate memory appropriately, 5. Final item is to extend your code from subtask number two, such that upon entering processtree # MAXIMUM DEPTH IS 5 a process tree should be printed. Each process in the tree should report its pid, parent's 2 pid and generation (i.e. the child of the first parent will belong to the first generation, it's children will belong to the second generation etc.). Another important aspect, cach process should be tabulated as many times as there are generations from the parent process. You should use a for loop for spawning the processes, and a variable as the generation counter. To achieve similar output, the parent branch after calling fork() should only wait for the children. Hint: Chapter 3 actually provides a lot of code that can be retised. Hint: To display output right away, you can tise fflush(stdout). 3 Input/Output format For this assignment, you don't have to make sure that input/output redirection works. Please refer to sample execution.txt and sample execution 2.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!