c programming in linux
Budget: $10 – $30 USD
Description
You will write a program named myshell that is capable of executing user's commands. Your program should print out a prompt: myshell> when it is ready to accept input. It must read a line of input, accepting several possible operations. This is a very simple shell, so it only accepts two operations: run and exit.
1. The run operation will execute other programs specified by the users. For example:
run ls will execute ls.
run ls -l will execute ls -l
run date will execute date
run who will execute who
If user provides an unknown program, the shell should print out an error message.
run azzxcd will try to execute azzxcd but will fail.
myshell> run azzxcd
myshell: starting child pid 4324
myshell: No such file or directory azzxcd
2. The exit operation will just exit myshell.
3. If user enters an empty line or run by itself, do nothing and return to the prompt.
myshell>
myshell> run
myshell>
4. If the user enters operationss other than run or exit, the shell should print out an error message:
myshell> start ls
myshell: start is not a valid operation
5. Additionally, myshell will also announce the pid of the child process.
i
System Calls
You will need to use the following systems calls: fork, wait, execvp, exit,... to implement this assigment.
Manual pages (man pages) will give you reference documentation for system calls. You also can use this online manual if you'd prefer.
Programming Assignment 2
The structure of your program should look like this:
1) In a loop, prompt the user for an operation and parameters. (Use fgets for this)
2) When a line of input is given, insert the operation and the parameters into an array of C strings. Use strtok to tokenize the string. Your program needs to exam the first word (using strcmp) to figure out whether the operation is a run, an exit, or something else. For simplicity, let's assume that users will not enter any line that have more than 20 words.
3) If the operation is run, fork a new process and have the parent wait for the child to complete. The child process will execute the given command using execvp.
4) Loop until the user enters exit
You will use the return value of all the system calls you use (fork, execvp, etc...) and the the global variable errno to perform error checking and to print out suitable messages in this assignment.
You will write a program named myshell that is capable of executing user's commands. Your program should print out a prompt: myshell> when it is ready to accept input. It must read a line of input, accepting several possible operations. This is a very simple shell, so it only accepts two operations: run and exit.
1. The run operation will execute other programs specified by the users. For example:
run ls will execute ls.
run ls -l will execute ls -l
run date will execute date
run who will execute who
If user provides an unknown program, the shell should print out an error message.
run azzxcd will try to execute azzxcd but will fail.
myshell> run azzxcd
myshell: starting child pid 4324
myshell: No such file or directory azzxcd
2. The exit operation will just exit myshell.
3. If user enters an empty line or run by itself, do nothing and return to the prompt.
myshell>
myshell> run
myshell>
4. If the user enters operationss other than run or exit, the shell should print out an error message:
myshell> start ls
myshell: start is not a valid operation
5. Additionally, myshell will also announce the pid of the child process.
i
System Calls
You will need to use the following systems calls: fork, wait, execvp, exit,... to implement this assigment.
Manual pages (man pages) will give you reference documentation for system calls. You also can use this online manual if you'd prefer.
Programming Assignment 2
The structure of your program should look like this:
1) In a loop, prompt the user for an operation and parameters. (Use fgets for this)
2) When a line of input is given, insert the operation and the parameters into an array of C strings. Use strtok to tokenize the string. Your program needs to exam the first word (using strcmp) to figure out whether the operation is a run, an exit, or something else. For simplicity, let's assume that users will not enter any line that have more than 20 words.
3) If the operation is run, fork a new process and have the parent wait for the child to complete. The child process will execute the given command using execvp.
4) Loop until the user enters exit
You will use the return value of all the system calls you use (fork, execvp, etc...) and the the global variable errno to perform error checking and to print out suitable messages in this assignment.