代做CSE 3100留学生作业、代写C/C++程序作业、代做Systems Programming作业、代写C/C++编程设计作业
CSE 3100 Systems Programming
Homework #5 Due: 10/23/2018
Complete your work in the hw5 folder. Remember to pull, add, commit, and push. You need to work on
three files only: execmd.c, workon.c, and runpipeline.c. Do NOT add other files.
Exercise 1. (100 points) runpipeline
A pipeline is a sequence of external programs chained together to perform a task. The standard output of
stage i of the pipeline is fed to the standard input of stage i + 1. In shells like bash, stages are separated
by "|". For example, the following pipeline that contains 7 stages counts the number of occurrences of each
word in a text file.1 The output of the last stage is redirected into file counts.txt. whitman.txt is in the
solutions repo under sol-hw5. You can also replace it with other text files, for example, your C source code.
cat whitman.txt | tr -s [:space:] '\n' | tr -d [:punct:] | tr A-Z a-z | sort | uniq -c | \
sort -nr > counts.txt
The seven stages do the following. The command in each stage prints its result to stdout and the output
of the last command is redirected to counts.txt.
1. Send the contents of the file whitman.txt to stdout
2. Replace every sequence of consecutive spaces in stdin with a single line-feed
3. Delete all punctuation characters from stdin and send remaining characters to stdout
4. Replace uppercase letters in stdin with lowercase letters
5. Sort the lines from stdin alphabetically
6. Collapse adjacent matching lines to a single copy preceded by the number of copies
7. Sort the lines from stdin in reverse numerical order
In this problem, you will compete the functions in runpipeline.c so the program can start a pipeline
with the programs specified at the command line. To avoid interference with the shell, pipeline stages are
separated with "--", instead of "|". To run the above bash pipeline with runpipeline, you would run the
following command in bash and the resulting counts.txt should be the same. Join two lines when you try
the command.
./runpipeline cat whitman.txt -- tr -s [:space:] '\n' -- tr -d [:punct:] -- tr A-Z a-z -- \
sort -- uniq -c -- sort -nr > counts.txt
In runpipeline.c, the commands for all stages are already stored in an array of Program structures,
which are defined as follows.
1 typedef struct program_tag {
2 char ** args ; // array of pointers to arguments
3 int num_args ; // number of arguments
4 int pid ; // process ID of this program
5 int fd_in ; // pipe fd for stdin
6 int fd_out ; // pipe fd for stdout
7 } Program ;
1The “\” at the end of first line allows the pipeline commands to continue on the next line; you can also just join the two
lines when you try the pipeline in bash.
1
args[0] is the command and args is the array of arguments to be passed to an execv* function. num args
is the number of arguments in args. pid is the process ID of the child process for this command. If fd in
is non-negative, the file descriptor will be used for stdin for the command. If fd out is non-negative, it will
be used for stdout for the command.
Note that runpipeline does not redirect the input or output for the pipeline itself. If needed, the
redirection can be set on runpipeline by the shell. Then the first command in the pipeline can have
redirected stdin and the last one can have redirected stdout.
Your program will start commands in start program(), one command at a time. You can create pipes
in the function for the command to be started, if any pipe needed has not been created yet, or you can create
all pipes for all stages in function prepare pipes().
Your code should close unused pipe FDs for/in each process, should not leave zombies behind, and should
not have memory leaks.
You can use lsof command to check the open files for processes. For example,
# list open files by PIDs
$lsof -p 3753,3754,3755,3756,3757
$lsof -p 3753
# list open files for processes whose name starts with runp, cat, wc, or tr
lsof -c runp -c cat -c wc -c tr
# use -u option to specify a user name. -a indicates combine conditions with 'and'
lsof -c runp -u netid -a
The rows that you should pay attention to are the ones that have a number in the FD column. Most of
the commands have only three open files 0, 1, and 2. Some commands, for example, tee, may have additional
open files.
Dealing with many pipeline stages may look scary at the beginning. However, if you start with two stages,
and go on to three stages, four stages, and more, you will find out that seven stages are about the same as
three stages. You can test pipelines with various numbers of stages, as shown in the examples below. Note
that you can use tee to examine the data stream at the middle stages. To check if your code is producing
correct result or behaves correctly, run the same pipeline in bash (and use "|", instead of "--", to connect
stages).
./runpipeline echo 'Hello, world!'
./runpipeline echo 'Hello, world!' -- wc
./runpipeline echo 'Hello, world!' -- cat -- wc
./runpipeline echo 'Hello, world!' -- cat -- cat -- wc
./runpipeline ls -- cat -- tee t.out -- wc
./runpipeline cat -- cat -- tee t.out -- cat -- wc
http://www.6daixie.com/contents/13/2035.html

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

微信:codinghelp

转载于:https://www.cnblogs.com/PYTHON26/p/9862787.html

CSE 3100 Systems Programming相关推荐

  1. TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) ABCD

    A 题意: 有一个开关,每天s点开,t点关(可能在第2天或第n天),判断x点时开着还是关着. 思路: 按照是否需要隔夜分个类. #include<bits/stdc++.h> using ...

  2. Atcoder TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) B - Takahashi‘s Secret

    题目链接:B - Takahashi's Secret (atcoder.jp) Problem Statement Takahashi has N friends. They have nickna ...

  3. Atcoder TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) C - Final Day

    题目链接:C - Final Day (atcoder.jp) Problem Statement N students are taking a 4-day exam. There is a 300 ...

  4. Paradigm Shifts in Kernel Programming 内核编程的范式转移

    Paradigm Shift in Kernel Programming 内核编程的范式转移 Raymond Kwan 这篇小文章主要分析了操作系统内核编程中主要使用C和命令式范式的原因,同时讨论了其 ...

  5. 想从事分布式系统,计算,hadoop等方面,需要哪些基础,推荐哪些书籍?--转自知乎...

    作者:廖君 链接:https://www.zhihu.com/question/19868791/answer/88873783 来源:知乎 分布式系统(Distributed System)资料 & ...

  6. 个人网页、博客、课程--不断更新

    论文和相关代码 :https://paperswithcode.com/ Caiming Xiong http://www.stat.ucla.edu/~caiming/ 论文,代码,博客 肖小粤的啵 ...

  7. 分布式系统(Distributed System)资料

    分布式系统(Distributed System)资料 <Reconfigurable Distributed Storage for Dynamic Networks> 介绍:这是一篇介 ...

  8. BiliBili 100+国际名校免费公开课整理分享

    本资源这是一份公开课的目录,这里的视频大多来自 YouTube 等国内无法访问的网站,为了方便国内的朋友观看,作者将这些视频搬运到了BiliBili. 资源整理自网络,源地址:https://gith ...

  9. 嵌入式程序员应知道的基本问题-C语言(zz)

    来源:21ICbbs  作者:lhf C语言测试:想成为嵌入式程序员应知道的0x10个基本问题 其中少量灰色的文字是我添加的,表达一些我的看法,很不成熟,希望朋友们指正. C语言测试是招聘嵌入式系统程 ...

最新文章

  1. 导入导出Android手机文件
  2. python 画云图_【词云图】如何用python的第三方库jieba和wordcloud画词云图
  3. 写给中学生的算法入门:学代码之前看这篇就够了
  4. mac下sublime text的使用
  5. 裁员潮来袭!IT行情雪崩之下,我靠它竟能逆向突破职业危机
  6. 照着教程装oracle却报错,手把手演示win7系统安装oracle10g程序遇到“程序异常终止。发生内部错误...”的操作教程...
  7. 基于网络安全相关的开源项目技术预研分析报告
  8. AutoRunner 功能自动化测试项目实训之第二个实战案例(五)
  9. “996”引众怒,互联网疯狂的后遗症
  10. 串口总线舵机之舵机命令
  11. iOS 音乐播放器demo讲解
  12. 启发式算法 Heuristic
  13. CentOS Install Passenger for ROR
  14. linux文件重定向 dup,linux之dup和dup2函数解析
  15. ckplayer播放线上视频问题
  16. 摩托车新手驾驶教程[4]
  17. linux下raid(md)驱动源码解析
  18. 家电类CCC认证流程
  19. 破解加密文档以及宏口令
  20. 【JS面试题】面试官问我:遍历一个数组用 for 和 forEach 哪个更快?

热门文章

  1. Excel如何设置单元格行高,办公入门
  2. 2022-2028年中国散热产业深度调研及投资前景预测报告(全卷)
  3. 2022-2028年中国橡胶履带产业发展动态及投资趋势预测报告
  4. 2022-2028年中国复合软管行业市场行情动态及发展趋向分析报告
  5. 实现SSTab单个选项卡代码
  6. Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)
  7. kwargs.pop是什么意思
  8. LeetCode简单题之重新排列数组
  9. 先进机器人系统中的关键技术
  10. CVPR2020:三维实例分割与目标检测