You are to write a C program that will essentially read a text file for a list of commands and will execute those commands in a pipeline: cmd1 | cmd2 |cmd3………….| cmdn First pass: congaline1.c This version does not need to handle the situation where the cmd’s have arguments. It reads the textfile containing the commands from stdin. To (minimally) test your program we suggest you write 3 small programs: addone.c that reads (text) integers from stdin and writes those integers (incremented by one) to stdout. addone_in.c that opens an inputfile (“inputfile” – “hard wired” into the program) and reads (text) integers from the file and writes those integers (incremented by one) to stdout. addone_out.c that opens an outputfile (“outputfile” – “hard wired into the program) and reads text integers from stdin and writes those integers (incremented by one) to the opened file. If you have written congaline1.c properly then if “inputfile” contains the number 1 and the textfile of commands contains: ./addone_in ./addone ./addone ./addone ./addone_out then after running conglaline1 outputfilename or ./addone outputfilename or ./addone –i inputfilename ./addone ./addone ./addone ./addone –o outputfilename Extra challenge (again not marked) – dream up some more interesting examples that actually do something useful with standard unix commands piped together. Submission – instructions will be posted shortly. HINT Pseudo-code to create a set of cmds piped: for cmd in cmds if there is a next cmd pipe(new_fds) fork if child if there is a previous cmd dup2(old_fds[0], 0) close(old_fds[0]) close(old_fds[1]) if there is a next cmd close(new_fds[0]) dup2(new_fds[1], 1) close(new_fds[1]) exec 代写C编程、C课程设计代写留学生、代做C程序、C语言代做留学生、代写C编程、congaline 实验代写cmd || die else // is parent if there is a previous cmd close(old_fds[0]) close(old_fds[1]) if there is a next cmd old_fds = new_fds if there are multiple cmds close(old_fds[0]) close(old_fds[1]) see: http://stackoverflow.com/questions/916900/having-trouble-with-fork-pipe-dup2-andexec-in-c/ (Links to an external site.)Links to an external site. Detailed Submisison Instructions The handin key for this exercise is: prac2. The following SVN commands will enable you to make a repository for this assignment. Please note the following: • Perform. these steps in the order written once only! • Replace aaaaaa, where it appears in the commands, with YOUR student id. • Some commands are long — they must be typed on one line. Use the Unix “cd” command to change to the place where you want your exercise directory to be stored, then type these commands: svn mkdir --parents -m &"spc prac2 start&" https://version-control.adelaide.edu.au/svn/a1aaaaaa/2018/s1/spc/prac2 (creates this directory in your svn tree) svn co https://version-control.adelaide.edu.au/svn/a1aaaaaa/2018/s1/spc/prac2 . (checks out a working copy in your directory) You can now begin work. You can add a file to the repository by typing the commands: svn add NAME-OF-FILE svn commit -m &"REASON-FOR-THE-COMMIT&" where “reason-for-the-commit” should be some brief text that explains why you changed the code since the last commit. Note that you only need to add a file once — after that, SVN will “know” it is in the repository. You are now ready to commence working on the exercise. The files you handin must include: 1. Your C source files as specified above. 2. A Makefile that will compile your C sources as specified above. You do not have to include any of the add_one.c files or their variants... that you used for testing we will supply those. & 转自:http://ass.3daixie.com/2018060448780670.html
讲解:C、C、C、C、C、congaline
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。