1cstream(1) BSD General Commands Manual cstream(1)
2
4 cstream — direct data streams, with bandwidth limiting, FIFO, audio,
5 duplication and extended reporting support.
6
8 cstream [-b num] [-B num] [-i filename] [-I string] [-l] [-n num]
9 [-o filename] [-O string] [-p filename] [-t num] [-T num]
10 [-v num] [-V] [filename]
11
13 Cstream filters data streams, much like the UNIX tool dd(1). It has a
14 more traditional commandline syntax, support for precise bandwidth limit‐
15 ing and reporting and support for FIFOs. Data limits and throughput rate
16 calculation will work for files > 4 GB.
17
18 Cstream reads from the standard input and writes to the standard output,
19 if no filenames are given. It will also 'generate' or 'sink' data if
20 desired.
21
22 Options:
23
24 -b num Set the block size used for read/write to num. The default is
25 8192 bytes.
26
27 -B num Buffer input up to num bytes before writing. The default is the
28 blocksize. It is an error to set this to anything below the
29 blocksize. Useful when writing tapes and simlilar that prefer
30 few large writes of many small.
31
32 -c num Concurrent operation. Use a seperate process for outout. This
33 is especially useful in combination with the -B option.
34 0 = use one process only (default)
35 1 = read process will buffer
36 2 = write process will buffer
37 3 = both processes will buffer.
38 In combination with a large buffer size this will often
39 load your memory heavily, everytime the reader transfers
40 the buffer it collected to the writer. If you use -c 3 and
41 have a buffer size of 128 Megabytes 256 MB of memory will
42 be touched at once.
43
44 -i num
45
46 -o num Set the file names to use for input or output, respectivly. If
47 the output file name is "-", data will just be discarded. If
48 the input file name is "-", data will be generated 'out of the
49 void'. If these options aren't given, stdin/stout will be used.
50 If you need to give -o or -i options and want stdin/stdout,
51 specify the empty string, like this:
52
53 cstream -i''
54
55 If TCP support has been compiled in (default), hostname:port‐
56 number will try to connect to the specified host at the speci‐
57 fied port and :portnumber will open a TCP socket on the local
58 machine and wait for a connection to arrive. SECURITY NOTE:
59 cstream includes no mechanism to restrict the hosts that may
60 connect to this port. Unless your machine has other network
61 filters, anyone will be able to connect.
62
63 -I string
64
65 -O string
66 Specify the type of input and output file, respectivly.
67 If string
68 includes 'f', a fifo will be created.
69 If string
70 includes 'a', the file will be assumed to be a opensound-
71 compatible audio device and will be switched to CD-like
72 settings.
73 If string
74 includes 't', a copy of the stream will be sent to file
75 descriptor 3.
76 If string
77 includes 'N', TCP will not be used for that file even if
78 the name has a ":".
79
80 -l Include line count in statistics.
81
82 -n num Limit the total amount of data to num. If there is more input
83 available, it will be discarded, cstream will exit after the
84 limit has been reached. If there is less input, the limit will
85 not be reached and no error will be signaled.
86
87 num may have a trailing 'k', 'm' or 'g' which means Kilobytes,
88 Megabytes or Gigabytes (where Kilo = 1024). This applies to all
89 numeric options.
90
91 -p filename
92 Write the process id of cstream to filename. If cstream uses a
93 seperate writer process (option -c), this is the pid of the
94 parent (reader) process.
95
96 -t num Limit the throughput of the data stream to num bytes/second.
97 Limiting is done at the input side, you can rely on cstream not
98 accepting more than this rate. If the number you give is posi‐
99 tive, cstream accumulates errors and tries to keep the overall
100 rate at the specified value, for the whole session. If you give
101 a negative number, it is an upper limit for each read/write
102 system call pair. In other words: the negative number will
103 never exceed that limit, the positive number will exceed it to
104 make good for previous underutilization.
105
106 -T num Report throughput every num seconds.
107
108 -v num Set verbose level to num. By default, it is set to 0, which
109 means no messages are displayed as long as no errors occur. A
110 value of 1 means that total amount of data and throughput will
111 be displayed at the end of program run. A value of 2 means the
112 transfer rate since the end of the first read/write pair will
113 also be reported (useful when there is an initial delay). A
114 value of 3 means there will also be seperate measurements for
115 read and write. This option is resource-consuming and currently
116 isn't implemented. A value of 4 means that notices about each
117 single read/write will be displayed. High values include all
118 message types of lower values.
119
120 -V Print version number to stdout and exit with 0.
121
122 filename A single filename as the last argument without an option switch
123 will be used as input file if -i has not been used.
124
125 SIGUSR1
126
127 SIGINFO Sending SIGUSR1 (or SIGINFO, which is usually mappend to Con‐
128 trol-T on you keyboard) to cstream causes it to display
129 throughput rates to stderr. The stream will continue as if
130 nothing happend.
131
132 SIGUSR2 Exit and report throughput rates, if requested.
133
134 SIGHUP I found myself sending SIGHUP accidentially too often. But
135 ignoring or misusing SIGHUP is not an option for me. Thus, when
136 cstream received SIGHUP, it will wait 5 seconds for another
137 SIGHUP, to give users a chance to correct a possible mistake.
138 If no additional SIGHUP is received, cstream kills itself with
139 SIGHUP.
140
142 cstream -o tmpfile -v 1 -n 384m -i -
143 Writes 384 Megabytes of unspecified data to file tmpfile and dis‐
144 play verbose throughput rate. Makes a good benchmark, the speed
145 of /dev/null varies too much from system to system.
146
147 cstream -i tmpfile -v 1 -n 384m -o -
148 Read the same file back in and discard data.
149
150 cstream -b 2000 -t 10000 /var/log/messages
151 Will display the file in a more or less watchable speed.
152
153 dump 0sf 400000 - / | cstream -v 1 -b 32768 -o /dev/rst0 -p pidfile
154
155 kill -USR1 `cat pidfile`
156 Write the output from dump(1) to tape. Each time the signal is
157 sent, the throughput and data rate so far will be displayed.
158
159 cstream -t 176400 -i /dev/dsp0 -I f -o -
160 Makes kind of a soundcard emulator which may be used to test
161 audio applications that need something to write to that limits
162 the data rate as a real soundcard does. This obviously doesn't
163 work when the application tries to write data using mmap(2) and
164 the application has to ignore errors when it tries to set sound‐
165 card parameters using ioctl(2).
166
167 cstream -t 176400 -i /dev/dsp0 -I f -o /dev/dsp1 -O f
168 Similar soundcard emulator, except that it allows you to grab the
169 data your applications sends to it from the other fifo, while
170 still having precise timing.
171
172 cstream -Oa -o /dev/dsp0 myhost.mydomain.com:17324
173 Connects port 3333 on host myhost.mydomain.com and whatever data
174 it finds there will be sent to the soundcard, with appropriate
175 settings for CD quality stero play.
176
177 cstream -i myaudiofile.raw -o :17324
178 This will open a TCP server on port 17324 and waits until someone
179 connects (for example, the commandline from the previous exam‐
180 ple). Then it will send the contents of myaudiofile.raw down the
181 TCP stream (for the previous audio example, typically a CD audio‐
182 track like you get from the tosha or cdparanoia utilities).
183
184 cstream -OD -o myfile
185
186 Write to file myfile with O_DIRECT. That usually means that the
187 filesystem buffer cache will not try to cache this file. You can
188 use that to prevent copying operations from eating up physical
189 memory. Note that when cstream encouters a write error it will
190 switch the output file from O_DIRECT to a normal file and write
191 all further blocks without O_DIRECT if writes without O_DIRECT
192 succeed. In practice that usually means that your last block, if
193 not a multiple of the filesystem block size, will still be writ‐
194 ten into the file (the maximum amount of data written without
195 O_DIRECT is your blocksize minus one). That way cstream ensures
196 that the output file has the length of the input, however odd the
197 length was and no matter what restrictions your OS places on
198 O_DIRECT output. Again, cstream will *not* pad the output to the
199 block size, you get the same file and file size as if not using
200 O_DIRECT, at the cost of switching to non-O_DIRECT whenever a
201 block is not the right size.
202
203 cstream -i :3333 | dd obs=8192 | ./cstream -omyfile -v7 -OD
204 This is what you need to do to buffer TCP input, so that the last
205 cstream will not switch away from O_DIRECT prematurely because of
206 short reads. If your input can do short reads (e.g. from TCP),
207 and you want to ensure that O_DIRECT stays in effect, you need a
208 buffer between the TCP stream and the O_DIRECT stream. Since
209 cstream does not yet support different input and output block
210 sizes, dd is suitable here. Note that this is only neccessary if
211 the OS requires multiples of the filesystem block size for
212 O_DIRECT. At the time of this writing this construct is needed
213 on Linux for using TCP streams with O_DIRECT, but it is not
214 needed on FreeBSD.
215
216 cstream -OS -o myfile
217 Writes to file myfile with O_SYNC. This means by the time the
218 system call returns the data is known to be on disk. This is not
219 the same thing as O_DIRECT. O_DIRECT can do its own buffering,
220 with O_SYNC there is no buffering at all. At the time of this
221 writing, O_SYNC on both Linux and FreeBSD is very slow (1/5th to
222 1/10th of normal write) and O_DIRECT is reasonably fast (1/4th to
223 1/2 of normal write). You can combined O_SYNC and O_DIRECT.
224
226 Exit code 0 means success.
227
228 Exit code 1 means a commandline syntax usage error.
229
230 Exit code 2 means other errors, especially system errors.
231
233 There should be an option to begin writing directly after the first read
234 ended and then fill the buffer with reads in the background. Right now
235 writing will not begin before the reader has filled the buffer completely
236 for the first time.
237
238 Not a bug: the code to do O_DIRECT is reasonably sophisticated. It will
239 fall back to normal I/O on errors. But before doing that it knows about
240 both filesystem blocksize requirements (will default I/O blocksize to
241 whatever the filesystem of the output file is in) and page alignment
242 requirements (I/O will happen from a page-aligned buffer). However, the
243 combination of concurrent read/writes (-c options) and O_DIRECT has not
244 been tested bejond basic verification that it gets some tests right.
245
247 dd(1), mkfifo(2)
248
250 cstream was initially written by Martin Cracauer in 1998. For updates
251 and more information see http://www.cons.org/cracauer/cstream.html
252
253BSD March, 30, 1999 BSD