Starting from:

$10

Unix systems calls

Using Unix systems calls, fork(), wait(), read() and write(), write a C program for integerbasic arithmetics to perform the followings:
• writes the message "This program makes simple arithmetics",
• gets in an infinite loop then
1. writes the message "Enter an arithmetic statement, e.g., 34 + 132 ",
2. reads the whole input line,
3. forks and
– the parent writes the message "Created a child to make your operation, waiting" then calls wait() to wait for its child.
– the child process calls the function childFunction(char *) and never returns.
4. the child, through childFunction(char *line),
– writes the message "I am a child working for my parent"
– uses sscanf() to convert the input line into an integer, a character and an integer,
respectively.
– in case of wrong statement, the child calls exit(50)
– in case of division by zero, the child calls exit(100)
– in case of a wrong op the child calls exit(200)
– otherwise, it performs the appropriate arithmetic operation,
– uses sprint() to create an output buffer consisting of n1 op n2 = result,
– writes the output bufferto the screen
– calls exit(0)
5. once the child terminates, the parent checks the returned status value and if it is
50, 100 or 200, writes "Wrong statement", "Division by zero" or "Wrong operator",
respectively.
6. the parent goes back to 1.
Important:
• All reads/writes must be done using read()/write()
• You can use the returned value of sscanf() for detecting a "Wrong statement"

More products