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

WE NEVER WANT TO TAKE PROGRAMS LIKE bash OR csh FOR GRANTED, SO WE WILL CREATE O

ID: 3887119 • Letter: W

Question

WE NEVER WANT TO TAKE PROGRAMS LIKE bash OR csh FOR GRANTED, SO WE WILL CREATE OR BUILD OUR OWN SHELL FROM SCRATCH - SLUSH

DESCRIPTION

slush is a very simple command-line interpreter. It uses a different syntax than shells like bash, and has much less functionality. slush executes in a loop in which it displays a prompt, reads in a command line from standard input, and executes the command.

There are two types of commands: built in commands which are executed by slush itself, and program execution commands which are carried out by separate processes.

A built in command must appear on a line by itself. The only built in command is:

cd dir - change current directory to dir

Program execution commands have the form:

prog_n [args] ( ... prog_3 [args] ( prog_2 [args] ( prog_1 [args]

This command runs the programs prog_n, ... , prog_2, prog_1 (each of which may have zero or more arguments) as separate processes in a "pipeline". This means the standard output of each process is connected to the standard input of the next.

The syntax of slush is backwards from shells you're used to, and is intended to emphasize the functional nature of pipeline commands. As an example, the command line:

more ( sort ( ps aux

should produce a paginated, sorted list of processes.

slush should catch ^C typed from the keyboard. If a command is running, this should interrupt the command. If the user is entering a line of input, slush should respond with a new prompt and a clean input line.

slush will exit when it reads an end-of-file on input.

ERROR HANDLING

If a program name does not exist or is not executable, slush should print an error message of the form:

prog1: Not found

(To do this automatically, you can use perror() after the exec() fails).

Syntax errors such as:

more ( ( ps au

more ( ps au (

should be handled with an appropriate message, such as:

Invalid null command

HINTS

1) Work on parsing before you work on functionality. First write your program so that it reads input and generates correct tokens.

2) Exiting on end-of-file (EOF) is VERY IMPORTANT because without it I cannot test your program. This is the only way to exit slush. You can create a EOF by typing ^D at the keyboard, or by running your program with noninteractive input. For example, echo ls | slush should run slush, execute the ls command, and quit slush. I suggest you read input using fgets()- the return value is false (0) on EOF.

3) To break the user input into tokens, you could use the the strtok() function. For simplicity, you may restrict each command in a pipeline to at most 15 arguments. You may also limit the length of an input line to 256 characters. Violations of these limits may result in an error or simply be ignored, so long as slush does not crash.

4) Turning the command into a pipeline of running processes is much easier if you write a recursive function. Start at the left end of the command string, and work right recursively. Processes should fork() off right to left as you return from the series of recursive calls.

5) When a process has a pipe, it needs to close() the file descriptor for the end of the pipe it's not going to use (or else it will never terminate). Do this after each fork(). Both parent and child may need to close something. Count your children... you'll need to wait() for them later.

6) Save the ^C handling for last. ^C generates a SIGINT signal. You need to set up a signal handler to catch the signal. What happens if a signal is caught while reading a line of input? How about if a signal is caught while wait() is waiting? One more hint for ^C handling: typing ^| will send a SIGQUIT and stop your process if you've screwed up ^C.

HELP IN C LANGUAGE PLEASE.

Explanation / Answer

Over the weekend, the Solar Roadways project on Indiegogo reached its target of $1 million. At the time of publishing, that figure is now north of $1.4 million, with five days left to go. The concept is verging on utopian: By replacing the USA’s concrete and asphalt roads with solar panels, we could produce three times more electricity than we consume, instantly solving just about every energy problem we have (geopolitical stuff, reliance on fossil fuels, CO2 production, etc.) It’s not hard to see why Solar Roadways has attracted so much attention and money: On paper, it really does sound like one of the greatest inventions ever. In reality, though, where, you know, real-world factors come into play, it will probably never make the jump from drawing board to large-scale deployment.

Solar Roadways, the brainchild of Julie and Scott Brusaw of Idaho, have been in development since at least the mid-2000s. The concept, as described by dozens of videos and blog posts over the years, is pretty simple: We replace roads with hard-wearing solar cells. By adding other electronics, such as LEDs and touch sensors, additional functionality has also been mooted: Illuminated road markings (and animals crossing the road), roads that melt snow and ice, and so on. Electrified/networked roadscould also be a key step towards self-driving cars and wide-scale EV adoptio