Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
An Introduction to Operating Systems Sharif University of technology Fall 1385 Computer Assignment #2 Due: Tuesday 14/9/85 Note: All of assignments should be done by groups of one or two person! There is no extra bonus for one-person groups. Ask us if you have any question or grey area about the assignment. All programs must be written in C/C++ (under Linux operating system of course!) You must use make to build your programs. You can find the Linux-Programming-Unleashed & Linux Advanced Programming books in the http://ce.sharif.edu/courses/8586/1/ce424/index.php/section/resources/file/resources Please send your CA source code to [email protected] before delivering it in the following format: Subject: Computer Assignment2 Body: first and last name and student ID of each member. Attachment: Source code: family1_family2.zip 1. Bash and External commands: Complete your bash in the previous assignment. Add the capability of executing external commands and running the programs from your bash. Your bash should support executing commands in background too. This means that when your bash executes one command, it should be able to execute next command without waiting for the termination of the process related to the first command. Example of executing normally: >> cmd arg1 arg2 … argn >> cp –r /root/temp.txt /home/SHMB/ Example of executing in background: >> cmd arg1 arg2 … argn & >> cp –r /root/temp.txt /home/SHMB/ & Note that if there is a common command among internal and external ones, you must execute the internal command. Hint: See manual version 3 of Linux for exec series commands (man 3 exec) and also see the manual for fork command. Also take a look at Linux-Programming-Unleashed book, chapter 11, System calls and library function section. 2. Introduction to IPC and Signaling. Suppose that you want to add a history command to your bash. This means adding an internal command (say history) which return last N commands that user executed. For some reason we don’t want to save the history list in the bash process itself. Instead you should write a program (say logger) which save this historical information and provides some services too. The whole thing you should do is, after each command entered by user, send a signal to logger process to inform it you have a request. (If there is no logger process in the system do nothing.) And then using one of IPC method such as pipe, shared memory, message passing, etc (do not use socket programming) transform the command name to logger. On the other hand the logger waits for a signal, after it receive the signal using IPC get the history command and save it to some structure. For simplicity consider that you should save some constant number of history commands. History command: This is a new internal command, you should add to your bash. It gets an argument (say N) and return N last commands user requested. Like adding a new command to logger, at first you should send a signal to logger process to inform it you have a request. This time using IPC you should give the logger N, and then get the result and show them to user Example: myshell >> ls . .. temp1 temp2 myshell >> cd temp1 myshell >> history error: there is no logger process running in the system. myshell >> ls . .. shell.cpp shell.h logger myshell >> ./logger myshell >> chertopert error: no such file or directory or command myshell >> cd .. myshell >> ls . .. temp1 temp2 myshell >> history 10 chertopert cd ls history myshell >> history 3 ls history history Hint: 1. Since the bash itself execute logger program, it can identify logger’s PID simply. 2. See manual of Linux for fifo and signal commands (man fifo, man signal) and also take a look at the Linux-Programming-Unleashed book.