CSE 3100 Systems Programming

news/2024/11/20 19:47:44/

代做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

 

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

微信:codinghelp

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


http://www.ppmy.cn/news/152921.html

相关文章

对比RS9113 CC3100 无线WIFI芯片

之前做过CC3100 现在就做RS9113, 易用性:CC3100完胜。 两个WIFI模块都可以通过SPI接口来控制,但是我用的时候,发现其实有很大的区别, CC3100 官方提供的是simple link 光听名字就比较简单,而RS9113官方…

poj 3100

题意&#xff1a;给你两个数B、N&#xff0c;求一个数的N次方最接近B。 先求出B的1/N次方&#xff1a;A&#xff0c;然后比较A和A1的N次方那个更接近B #include<stdio.h> #include <math.h> int main() {double a,b,n;while(1){scanf("%lf%lf", &b,&…

3100

1 /* 2 这题真没意思&#xff0c;太水了。枚举就可以&#xff0c;我还想了二分的思想 3 */ 4 5 // include file 6 #include < cstdio > 7 #include < cstdlib > 8 #include < cstring > 9 #include < cmath > 10 #include < cctype > 11 #…

nbs3100支持snmp功能吗?

nbs3100是一种型号&#xff0c;如果指的是某个具体的设备&#xff0c;我无法确定其是否支持SNMP功能。SNMP是一种网络管理协议&#xff0c;用于收集和组织网络设备的信息&#xff0c;例如路由器、交换机和服务器等。如果nbs3100是一种网络设备&#xff0c;并且其规格表明支持SN…

计算机电源 n305p-04,N255PD-00 L305P-00 L305P-01 N305P-00 305W DELL电源

DELL电源 型号:N255PD-00,通用L305P-00,L305P-01,N305P等 本电源适用于戴尔Dimension 3100,5100,5150,9100 Optiplex 210L,320,330 360 GX520,E520 GX620,745 755等。 电源型号:N255PD-00,与L305P-00,L305P-01,N305P-01等通用,线才接口:24针+4个SATA接口+1…

bzoj 3100 排列

题目大意: 给你长度为 \(1e6\) 的序列, 求最大的 \(K\) 使得序列中含有一个 \(K\) 的排列 做法: 性质: 区间包含1, 元素不重, 区间最大值区间长度 枚举一个 \(1\) 让答案区间包含它 不妨设区间的最大值在 \(1\) 右边 two-pointer扫描右端点, 维护元素不重区间的极小左端点 判断…

bzoj3100 排列

这个题有点恶心啊&#xff0c;总觉得以前做过&#xff0c;可就是想不出来。最后在发现是meng神出的一次模拟赛题 当时我还P都不会呢... 这个题有两个关键点&#xff0c;一个是选取的子序列内不能有重复&#xff0c;二是选取的子序列要是一个排列(当然这包含了一)。首先如果确定…

x3100服务器设置linux启动,IBM System x3100服务器常见问题解答

【IT168 资讯】 Q) x3100 都能安装哪些操作系统? Q) x3100 的市场定位及目标应用是怎样的? Q) x3100 能做RAID吗? Q) x3100 能插几块硬盘?最多支持多大硬盘容量? Q) x3100 有多少个内存插槽?扩展内存有什么要求? Q) x3100 有ps/2的键盘鼠标接口吗?有串口和并口吗? Q) …