Have to use C or C++ for the following. I need help with the Linux/Unix system c
ID: 3620105 • Letter: H
Question
Have to use C or C++ for the following. I need help with the Linux/Unix system commands necessary to do this. I can write any necessary C code, but do not know what system functions I need to implement this problem.Assignment: Implement your own command line interpreter like a Unix shell program - an application program that gets commands from a keyboard and uses the system call interfaces to invoke OS functions.
Shell should support the following:
a) Support exit or stop your shell command Ex: exit
b) Support commands with no arguments Ex: ls, pwd
c) Support commands with arguments Ex: ls -l, cd directory
d) A command, with or without arguments, whose output is redirected to a file
Ex: ls>foo, ls -Fx >foob
e) Display error messages if the typed command has errors or cannot be found
f) Shell should isolate itself from program failures by creating a child process to execute each command specified by the user.
Method:
1) Print a prompt - when myshell is begun, display its own string as a prompt, "myshell>"
How do I change the prompt?
How do I perform a blocking read to get the command line?
If you could please give me some information on the above, such as which system functions I should use, it will really be appreciated. I do not expect anyone to write my program for me. Just need help to get started and know what is available to accomplish these tasks.
Thank you.
Explanation / Answer
Hi, For running a command with command line or without it, you can use popen system call. Refer it's man page, you will get more information. This will implement your b,c requirement. for a part ,just compare using strcmp function for exit.. for d part, use strstr function to find ">" then perform file operation using fopen. for e part, check return status of popen. for f part, use pthreade_create function to create threads. Still have problem, don't forget to ask...
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.