首页 > > 详细

讲解CSSE2310、讲解C++语音编程

The University of Queensland
School of Information Technology and Electrical Engineering
CSSE2310/CSSE7231 — Semester 2, 2022
Assignment 3 (version 1.3)
Marks: 75 (for CSSE2310), 85 (for CSSE7231)
Weighting: 15%
Due: 6:00pm Friday 7th October, 2022
Specification changes are shown in red - version 1.0 to 1.1, blue - version 1.1 to 1.2, and
green – version 1.2 to 1.3. Changes are summarised at the end of the document.
Introduction 1
The goal of this assignment is to demonstrate your skills and ability in fundamental process management and 2
communication concepts, and to further develop your C programming skills with a moderately complex program. 3
You are to create a program called jobthing, which creates and manages processes according to a job 4
specification file, and must monitor and maintain the status and input/output requirements of those processes. 5
The assignment will also test your ability to code to a programming style guide and to use a revision control 6
system appropriately. 7
CSSE7231 students will write an additional program, mytee which emulates some basic functionality of 8
the Unix tee command, as a further demonstration of your C programming, file and commandline handling 9
capabilities. 10
Student Conduct 11
This is an individual assignment. You should feel free to discuss general aspects of C programming and 12
the assignment specification with fellow students, including on the discussion forum. In general, questions like 13
“How should the program behave if hthis happensi?” would be safe, if they are seeking clarification on the 14
specification. 15
You must not actively help (or seek help from) other students or other people with the actual design, structure 16
and/or coding of your assignment solution. It is cheating to look at another student’s assignment code 17
and it is cheating to allow your code to be seen or shared in printed or electronic form by others. 18
All submitted code will be subject to automated checks for plagiarism and collusion. If we detect plagiarism or 19
collusion, formal misconduct actions will be initiated against you, and those you cheated with. That’s right, if 20
you share your code with a friend, even inadvertently, then both of you are in trouble. Do not post your 21
code to a public place such as the course discussion forum or a public code repository, and do not allow others 22
to access your computer – you must keep your code secure. 23
You must follow the following code referencing rules for all code committed to your SVN repository (not 24
just the version that you submit): 25
Code Origin Usage/Referencing
Code provided to you in writing this semester by
CSSE2310/7231 teaching staff (e.g. code hosted on Blackboard, posted on the discussion forum, or shown in class).
May be used freely without reference. (You must be able
to point to the source if queried about it.)
Code you have personally written this semester for
CSSE2310/7231 (e.g. code written for A1 reused in A3)
May be used freely without reference. (This assumes
that no reference was required for the original use.)
Code examples found in man pages on moss. May be used provided the source of the code is
referenced in a comment adjacent to that code. (Code
you have taken inspiration from must not be directly
copied or just converted from one programming
language to another.)
Code you have personally written in a previous enrolment
in this course or in another ITEE course and where that
code has not been shared or published.
Code (in any programming language) that you have taken
inspiration from but have not copied.
Other code – includes: code provided by teaching staff only
in a previous offering of this course (e.g. previous A1 solution); code from websites; code from textbooks; any code
written by someone else, or partially written by someone
else; and any code you have written that is available to
other students.
May not be used. If the source of the code is referenced
adjacent to the code then this will be considered code
without academic merit (not misconduct) and will be
removed from your assignment prior to marking (which
may cause compilation to fail and zero marks to be
awarded). Copied code without adjacent referencing will
be considered misconduct and action will be taken.
26
1 Version 1.3
Uploading or otherwise providing the assignment specification or part of it to a third party including online 27
tutorial and contract cheating websites is considered misconduct. The university is aware of these sites and 28
many cooperate with us in misconduct investigations. 29
The course coordinator reserves the right to conduct interviews with students about their submissions, for 30
the purposes of establishing genuine authorship. If you write your own code, you have nothing to fear from this 31
process. If you are not able to adequately explain your code or the design of your solution and/or be able to 32
make simple modifications to it as requested at the interview, then your assignment mark will be scaled down 33
based on the level of understanding you are able to demonstrate. 34
In short - Don’t risk it! If you’re having trouble, seek help early from a member of the teaching staff. 35
Don’t be tempted to copy another student’s code or to use an online cheating service. You should read and 36
understand the statements on student misconduct in the course profile and on the school web-site: https: 37
//www.itee.uq.edu.au/itee-student-misconduct-including-plagiarism 38
Specification – jobthing 39
jobthing reads a job configuration from a file whose name is provided as a command line argument. It creates 40
processes and runs programs according to that specification, optionally connecting those processes’ standard 41
input and output either to files, or jobthing itself via pipes. jobthing then reads input from stdin, interpreting 42
that input as commands that cause various actions to be taken, such as sending strings to the other processes, 43
reporting on statistics and so on. jobthing must handle certain signals and take specific action upon receiving 44
those signals. 45
Full details of the required behaviour are provided below. 46
Command Line Arguments 47
jobthing has one mandatory argument – the name of the job specification file, and also accepts several optional 48
arguments. These arguments may appear in any order. 49
./jobthing [-v] [-i inputfile] jobfile 50
• The optional -v argument, if supplied, puts jobthing into verbose mode, causing it to emit additional 51
debug and status information. Precise requirements are documented below. 52
• The optional -i inputfile argument is the name of a file which will be used to provide input to jobthing 53
and its managed processes. If no inputfile is specified (i.e. the -i argument is not given), then jobthing 54
is to take input from stdin 55
• The jobfile argument specifies the name of a file from which job information is to be read. This format 56
is documented below. This argument is mandatory. 57
If the user provides invalid options, too few or too many command line arguments, jobthing shall emit the 58
following usage information to stderr, and exit with return code 1: 59
Usage: jobthing [-v] [-i inputfile] jobfile 60
If the inputfile specified with the -i argument is unable to be opened for reading, then the following message 61
should be emitted to stderr and jobthing should exit with return code 3: 62
Error: Unable to read input file 63
This should be checked prior to attempting to open the job file. 64
jobthing basic behaviour 65
jobthing reads the job specification file provided on the command line, spawning child processes and executing 66
programs as required. In general, jobthing is required to maintain a constant process state, regardless of what 67
happens to those child processes and programs. For example, if a child process is killed or terminates somehow, 68
then, unless otherwise specified, jobthing is required to notice this, and re-spawn the job as required, up to 69
the maximum number of retries specified for each job. 70
Depending on the contents of the jobfile, each job created by jobthing may have its stdin and stdout 71
connected to a pipe (back to jobthing), or to a file on the filesystem. 72
2 Version 1.3
Once jobthing has created the initial set of jobs, it is to take input either from stdin, or from the file 73
specified with the -i inputfile commandline argument, one line at a time. By default each input line should 74
be sent to each job to which jobthing has a pipe connection, however a line starting with the asterisk character 75
‘*’ will be interpreted as a command. 76
After sending the input text to each job, jobthing will then attempt to read a line of input from each 77
job (again, only those to which jobthing is connected by a pipe). Output received from jobs is emitted to 78
jobthing’s standard output. 79
Upon reading EOF from the input (stdin or the input file), jobthing shall terminate. 80
jobthing job parsing 81
The job file provided to jobthing is a text file, with one line per job. 82
83
If jobthing is unable to open the job file for reading, it is to emit the following message to stderr, and 84
exit with return code 2: 85
Error: Unable to read job file 86
Lines beginning with the ‘#’ (hash) character are comments, and are to be ignored by jobthing. Similarly, 87
empty lines (i.e. with no characters before the newline) are to be ignored. 88
89
All other lines are to be interpreted as job specifications, split over 4 separate fields delimited by the colon (‘:’) 90
character as follows 91
92
numrestarts:input:output:cmd [arg1 arg2 ...] 93
94
where each field has the following meaning or intepretation (where “empty” means a zero length string): 95
• numrestarts – specifies how many times jobthing shall start or restart this job if it terminates. 0 96
(zero) or empty implies that jobthing shall restart the job every time it terminates, 1 (one) means that 97
jobthing should attempt to launch the job once only upon startup – if it terminates it is not restarted. 98
Other integers are interpreted similarly. 99
• input – empty implies that this job shall receive its standard input from a pipe connected to jobthing. 100
Otherwise, the named file is to be opened for reading and connected to this job’s standard input stream. 101
• output – empty implies that this job shall send its standard output to a pipe connected to jobthing. 102
Otherwise, the named file is to be opened for writing (with flags O_CREAT | O_TRUNC and permissions 103
S_IWUSR | S_IRUSR) and connected to this job’s standard output stream. 104
• cmd [arg1 arg2 ...] – the name of the program to be run for this job, and optional arguments to be 105
provided on the commandline to that program. Arguments are separated by spaces. Program names and 106
arguments containing spaces may be specified by enclosing them in double quotes. A helper function is 107
provided to make this easer, see the split_space_not_quote() function described on page 11. 108
Note: Individual job specifications are independent, and you do not need to consider if jobs might interact with 109
each other (e.g. sharing input or output files etc). We will only test job specifications that have predictable 110
and deterministic behaviour. 111
Note: The colon character has special meaning and will only appear in job files as a separator. You do not 112
need to consider, nor will we test for jobfiles that contain the colon character as part of a command name or 113
argument. 114
Note: See the split_line() function described on page 11 for an easy way to split the colon-delimited job 115
specifications. 116
117
Following are several sample jobfiles with explanatory comments:
# A job, running cat, stdin/stdout connected to jobthing. Only start 'cat' once
1:::cat
# A job, running cat, stdin/stdout connected to jobthing. Start 'cat' a maximum of 5 times
5:::cat
3 Version 1.3
# A job, running cat, stdin/stdout connected to jobthing.
# retries = 0 -> re-launch cat every time it terminates, no limit
0:::cat
# A job, running cat, take stdin from /etc/services, send stdout to foo.txt.
# Only run 'cat' once
1:/etc/services:foo.out:cat
# A job, running cat, take stdin from /etc/services, stdout connected back to jobthing
# Only run 'cat' once
1:/etc/services::cat
# two jobs, both running cat, stdin and stdout connected to jobthing.
# The first job runs cat only once, the second will restart it forever as required
1:::cat
0:::cat
If verbose mode is specified, for each valid job line read from the jobfile, jobthing should emit the following 118
output to its stdout 119
Registering worker N: cmd arg1 arg2 ... 120
where 121
• N is the replaced with job number, incrementing from 1 (one) 122
• cmd is the command to be run, and arg1, arg2, ... are any arguments provided to the command. Note 123
that there should be a single space between cmd and any arguments, and there should be no trailing space 124
on this line of output 125
The following is an example of such output: 126
Registering worker 1: cat
Registering worker 2: tee logfile.txt
A job line in the jobfile is invalid if any of the following conditions are met: 127
• There are not precisely 4 fields separated by colons 128
• The integer value first field (numrestarts) is not a proper, non-negative integer (if not empty) 129
• The cmd field in the job line is empty or starts with a space 130
Invalid job lines are to be ignored and are not given job numbers. Further, if verbose mode is specifed on 131
the command line, then jobthing shall emit the following to its stderr: 132
Error: invalid job specification: 133
where is replaced by the offending job specification line, e.g. 134
Error: invalid job specification: -10:0:foobar baz 135
jobthing startup phase 136
Once the jobfile has been read, jobs are to be created in the order they were specified in the job file. 137
• If an input file is specified for the job, jobthing shall attempt to open that file in read mode and the 138
job is to have its stdin redirected from that file. Otherwise, jobthing shall create a pipe, connecting 139
that job’s stdin to the reading end of the pipe, with jobthing holding the write end of the pipe through 140
which it will later send information. 141
4 Version 1.3
• Similarly, if an output file is specified for the job, jobthing shall attempt to open that file in for writing and 142
the job is to have its stdout redirected to that file. Otherwise, jobthing shall create a pipe, connecting 143
that job’s stdout to the writing end of the pipe, with jobthing holding the read end of the pipe through 144
which it will later receive information. 145
If a job has an input file specified, and that file cannot be opened, jobthing shall emit the following message 146
to stderr. The job shall be considered invalid unrunnable and no further handling or respawn attempts shall 147
be made for that job. (If an output file is also specified, no attempt shall be made to open it.) 148
Error: unable to open "" for reading 149
where is the name of the file from the job specification. 150
Similarly, if an output file is specified and cannot be opened for writing, the job is considered invalid 151
unrunnable, no further processing or spawn attempts are made, and jobthing shall emit to stderr: 152
Error: unable to open "" for writing 153
Once any input and output files and pipes are opened/created, jobthing shall spawn a new process for 154
each runnable job, connect the stdin and stdout of the new job as required, and then exec the command line 155
specified for the job. 156
If verbose mode is specified, then jobthing should emit the following to its stdout: 157
Spawning worker N 158
where N is replaced by the job number. 159
160
Important: jobthing shall ensure that all un-used file handles are closed before executing the job process. 161
That is, the job shall have only its standard input, output and error file handles open. (Standard error is just 162
to be inherited from jobthing.) Test scripts will check to ensure that no other file handles leak from jobthing 163
to individual jobs. 164
If the child’s exec call fails, the child process is to call _exit() with the return code 99. jobthing is not 165
expected to detect a failure to exec (e.g. such jobs don’t become unrunnable) – this is treated exactly the same 166
as a successful child execution where the child immediately returned exit status 99. 167
jobthing operation and command format 168
Once jobthing has started the jobs, it should sleep for one second and then enter an infinite loop (terminated 169
only by reading EOF on its input stream (stdin or the supplied input file) or by running out of viable workers 170
– see descriptions below). 171
Each time through the loop jobthing shall perform the following operations, in the exact order specified 172
below. 173
Note: Any jobs that were marked invalid unrunnable during the startup phase (i.e. because their input or 174
output files could not be opened) are excluded from all handling during this main loop. 175
1. Check on the status of each job (in the order they were specified in the job file), report on any jobs that 176
have terminated, and restart those which need to be restarted. 177
• for any jobs that have terminated since the last check, jobthing shall generate a line of output to 178
stdout in the following format: 179
Job N has terminated with exit code M 180
or 181
Job N has terminated due to signal S 182
depending on the reason for the job terminating. N, M and S should be substituted by the job number, 183
exit code or signal number as appropriate. 184
• close and clean up any pipes and file descriptors associated with communication to the terminated 185
job 186
• for each job that has terminated, if the total number of times it has been (re-)started is less than the 187
maximum number specified in the job file, then the job shall be restarted in exactly the same way it 188
was started (including input/output file redirection/pipes as required). Note that it is possible that 189
a respawning might not be possible due to the inability to open an input or output file for reading 190
or writing (even though that succeeded for an earlier run). In this case, jobthing should print the 191
5 Version 1.3
same error message as specified above (see “jobthing startup phase”) and make no further attempts 192
to respawn that job – i.e. the job becomes unrunnable. If the job is restarted and verbose mode is 193
specified, then jobthing shall emit the following to its stdout: 194
Restarting worker N 195
where N is replaced by the job number. 196
• If a job has already been restarted the maximum number of times, then it should not be restarted – 197
the job is now unrunnable. 198
2. If jobthing determines that there are no jobs running and no further possible jobs left to (re)launch (all 199
jobs are unrunnable), then it shall emit the following message to stderr, and exit with exit code 0 (zero): 200
No more viable workers, exiting
Reasons for this are 201
• No jobs remain with a non-zero restart count remaining 202
• No jobs remain that have valid input or output redirection files 203
3. Read a line of input from stdin or the specific jobthing input file, and process it as a command according 204
to the following requirements: 205
• If EOF is detected, then jobthing shall exit with exit status 0 (zero). 206
• Lines beginning with the asterisk ‘*’ character are treated as commands – see below for details. After 207
processing the command, jobthing shall sleep for 1 second and then return to the top of the main 208
loop, checking job status again etc. 209
• Any other lines are sent as-is to each job to which jobthing has a connection (i.e. a pipe exists 210
between jobthing and the job’s stdin). 211
• Data sent to each job is to be echoed to jobthing’s stdout in the following format: 212
ID<-’text’ 213
where ID is the job ID (starting from one), and ’text’ is the line of input sent to the job, surrounded 214
by single quotes. 215
4. jobthing shall sleep for 1 second 216
5. jobthing shall attempt to read exactly one line of input from each job to which it has a pipe connected 217
to that job’s stdout. Each line of output received from each job shall be emitted to jobthing’s stdout 218
as follows: 219
ID->’text’ 220
where ID is the job ID (starting from one), and ’text’ is the line of output received from the job, 221
surrounded by single quotes. It is expected that jobs will have a line of output available. If a job fails to 222
send such a line it is acceptable for jobthing to block until such time as a line is returned (or EOF is 223
detected). If EOF is detected, no message is output unless verbose mode is enabled. If verbose mode is 224
enabled then jobthing should output the following to stderr: 225
Received EOF from job N 226
where N is replaced by the job number. 227
6. Otherwise, jobthing shall repeat the loop starting back at Step 1 above. 228
NOTE: it is critical that you do these actions in this order, otherwise your program will behave differently and 229
fail many tests. 230
jobthing signal handling requirements 231
Upon receiving SIGHUP, jobthing is to emit to its stderr statistics on the history and status of each job that 232
was specified in the jobfile. Each line of the statistics report is of the format 233
234
jobnum:numstarts:linesto 235
where each field has the following interpretation: 236
6 Version 1.3
• jobnum – the number of the job, starting from one which is the first job in the provided jobfile 237
• numstarts – how many times jobthing has attempted to start or restart the job, including the initial 238
process creation upon startup 239
• linesto – how many lines of input jobthing has sent to the job. Jobs whose stdin is read from a file 240
(rather than a pipe from jobthing) will report 0 (zero). 241
Note that the statistics for any given job accumulate over multiple restarts – if a job is terminated and 242
respawned multiple times, the total number of lines sent to it over the lifetime of jobthing is reported. 243
jobthing shall block or otherwise ignore SIGINT (Control-C). 244
245
jobthing must gracefully handle the possibility that it attempts to write information down a pipe to a job that 246
has terminated. If this occurs, jobthing shall silently ignore this fact, and the terminated job and associated 247
pipes should be cleaned up as per normal processing, with the job being restarted if appropriate. 248
jobthing command handling 249
The following table describes the commands that must be implemented by jobthing, and their syntax. Addi- 250
tional notes on each command will follow. 251
Command Usage Comments
*signal *signal jobID signum Send the signal (signum – an integer) to the given job
(jobID).
*sleep *sleep millisec Sleep for millisec (an integer) milliseconds.
252
• Any invalid commands provided to jobthing (i.e. a command word starting with ‘*’ is invalid), shall 253
result in the following message to stdout: 254
Error: Bad command 'cmd'
where ’cmd’ is the offending command enclosed in single quotes 255
• if the command is not provided the correct number of arguments, the following is emitted to stdout 256
Error: Incorrect number of arguments
• All numerical arguments, if present, must be complete and valid numbers. e.g. “15” is a valid integer, but 257
“15a” is not. Your program must correctly identify and report invalid numerical arguments (see details 258
below for each command). Leading whitespace characters are permitted, e.g. “ 10” is a valid number – 259
these whitespace characters are automatically skipped over by functions like strtol() and strtod(). 260
• Any text arguments, including strings and program names, may contain spaces if the argument is surrounded 261
by double quotation marks, e.g. "text with spaces". A line with an odd number of double quotes will 262
be treated as though there is an additional double quote at the end of the line1
. A helper function is 263
provided to assist you with quote-delimited parsing, see the “Provided Library” section on page 11 for 264
usage details. 265
*signal 266
The *signal command shall cause a signal to be sent to a job. Exactly two integer arguments must be specified 267
– the target job ID, and the signal number. 268
If the job ID is invalid, your program should emit the following to stdout: 269
Error: Invalid job
Reasons for a job number being invalid are: 270
• an invalid integer, e.g. “23a” 271
• an invalid job number (less than 1, greater than the total number of jobs) 272
1This will not be tested
7 Version 1.3
• the specified job is unrunnable has terminated or is otherwise invalid (reached maximum number of 273
restarts, input or output files could not be opened) 274
If the signal number is invalid (non-numeric, less than 1 or greater than 31) then your program should emit 275
the following to stdout: 276
Error: Invalid signal
If all arguments are valid, the signal shall be sent to the targetted job. (There is no need to check whether 277
the job is still running when the signal is actually sent.) 278
*sleep 279
The *sleep command shall cause jobthing to sleep for the specified number of milliseconds. Exactly one 280
non-negative integer argument must be provided. 281
If the sleep duration value is invalid (not a properly formed integer, or a negative value), your program 282
should emit the following to stdout: 283
Error: Invalid duration
If the arguments are valid, jobthing shall sleep for the required duration (in milliseconds). 284
Example jobthing Sessions 285
In this section we walk through a couple of increasingly more complex examples of jobthing’s behaviour. Note 286
however that these examples, like provided test-cases, are not exhaustive. You need to implement the program 287
specification as it is written, and not just code for these few examples. 288
Consider a config file once_cat.txt with following contents: 289
1 1:::cat
This defines a single job, running cat, to be launched once only, and stdin and stdout connected via pipes 290
to jobthing. We launch jobthing in verbose mode and interact with the job in some simple ways. Note that 291
text formatted in bold is entered and echoed on the terminal, it is not output of jobthing itself. 292
1 $./jobthing -v once_cat.txt
2 Registering worker 1:cat
3 Spawning worker 1
4 hello there
5 1<-'hello there'
6 1->'hello there'
7 this is some text
8 1<-'this is some text'
9 1->'this is some text'
Thus we see simple job startup, and text passing to and from the job. Next we can explore the *signal 293
command (continuing the same session): 294
10 *signal 0 11
11 Error: Invalid job
12 *signal 1 45
13 Error: Invalid signal
14 *signal 23a 45
15 Error: Invalid job
16 *signal 1 9
17 Worker 1 terminated due to signal 9
18 No more viable workers, exiting
Here after several invalid *signal command attempts, we finally send signal 9 to worker 1, which causes 295
its termination. jobthing then determined that this job should only be launched once, and that with no more 296
viable runnable jobs to run it terminates. 297
We next consider job input and output redirection, with the file cat_once_in_out.txt: 298
8 Version 1.3
1 1:/etc/services:./foo.out:cat
This job file runs a single job, cat, but it takes its standard input from /etc/services, and redirects its 299
output to ./foo.out. It runs only once. 300
Launching this job, in verbose mode, we see the following: 301
1 Registering worker 1: cat
2 Spawning worker 1
3 Worker 1 terminated with exit code 0
4 No more viable workers, exiting
In this example, we see that the process was spawned, but because its input was redirected from a file, the 302
cat process ran to completion almost immediately. This was detected by jobthing, which identified that no 303
further restarts should be attempted, and that no runnable jobs remained, so the program exits without pausing 304
for any user input. 305
Let’s now consider a more complex example, with multiple processes and different run counts. The example 306
configuration file is mixed_multicat.txt: 307
1 0:::cat
2 1:::cat
3 2:::cat
Here we have three jobs, all to run cat with their stdin and stdout connected via pipes to jobthing, 308
however each has a different number of restarts: zero (i.e. re-start endlessly), 1, and 2. 309
1 $./jobthing -v mixed_multicat.txt
2 Hello
3 1<-'Hello'
4 2<-'Hello'
5 3<-'Hello'
6 1->'Hello'
7 2->'Hello'
8 3->'Hello'
Entering a single line of input (’Hello’) has it sent to each job in turn, then that same string is returned 310
from each job by the cat process. 311
We then kill job number 2, and send some more input: 312
9 *signal 2 9
10 Worker 2 terminated due to signal 9
11 Hello again
12 1<-'Hello again'
13 3<-'Hello again'
14 1->'Hello again'
15 3->'Hello again'
Here we see that job 2 was terminated and not restarted (its restart count was only 1), and that the 313
subsequent input (Hello again) was then only sent to remaining live jobs (1 and 3). Let’s send a signal to job 314
number 3, and send some more input: 315
16 *signal 3 11
17 Worker 3 terminated due to signal 11
18 Restarting worker 3
19 foobar
20 1<-'foobar'
21 3<-'foobar'
22 1->'foobar'
23 3->'foobar'
And again: 316
9 Version 1.3
24 *signal 3 11
25 Worker 3 terminated due to signal 11
26 baz
27 1<-'baz'
28 1->'baz'
After the second signal, worker 3 has finally terminated and not restarted, and the input entered at the 317
console is sent only to worker 1. Since worker 1 has a restart count of zero (restart forever), we can send it as 318
many signals as we like, it will continue being restarted: 319
29 *signal 1 5
30 Worker 1 terminated due to signal 5
31 Restarting worker 1
32 *signal 1 6
33 Worker 1 terminated due to signal 6
34 Restarting worker 1
35 still there?
36 1<-'still there?'
37 1->'still there?'
Finally, let’s send SIGHUP to jobthing, and see the statistics reporting: 320
38 1:cat:2:4
39 2:cat:1:1
40 3:cat:2:3
Here we can see how many times each job was restarted (including expired ones like jobs 2 and 3), and how 321
many lines of input were sent to each. 322
Specification - mytee (CSSE7231 students only) 323
CSSE7231 students are to write an additional program, called mytee. mytee reads lines of input from stdin, 324
and writes them back out to stdout, and also to another file whose name is provided on the command line. By 325
default, mytee creates a new output file every time it is run, however this can be overridden by providing the 326
-a command line option. 327
Command Line Arguments 328
mytee requires one mandatory argument – the name of the output file, and accepts one optional argument. 329
These arguments may appear in any order. 330
./mytee [-a] outfile 331
• The optional -a argument puts mytee into append mode. In this mode, if the specified output file already 332
exists, then mytee shall append content to it (add it at the end). Otherwise, and by default, mytee shall 333
overwrite the outfile. 334
• The outfile argument specifies the name of the file to which the input received from stdin should be 335
written. 336
Operation and errors 337
Once the required output file ha

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!