POSIX Projects
Here are a couple of *nix command line applications written in C.
POSIX Projectsholdon
A UNIX pipeline staller
Ever wanted to modify some file, for example a list of directories with grep or a similar filter:
$ grep -v "$removal" "$LIST_FILE" > temp-file $ mv temp-file "$LIST_FILE"Holdon addresses this, allowing you to use it to 'delay' writing to the file or stream until the input has finished. (as in reaches end of file)
$ grep -v "$removal" "$LIST_FILE" | holdon "$LIST_FILE"
Beware, holdon will quite happily eat all your memory then die without dumping the output. The reason for this is simple, you don't want to corrupt the list under any circumstances. So it is better to fail and leave it how it was than to leave it inconsistent.
Now you ask, why should you use holdon? If you want my professional opinion, you shouldn't. It's essentially caching a file write, and that is something we should trust the operation. The pipe/move trick is also atomic, so long as you check the exit code of the programs in the pipeline (before doing the move).
Source code download: holdon.c
Back to top
slowdown
A POSIX filter to slow down a pipeline.
This command limits the output rate of some other program. Useful for not much.
$ ./slowdown --help Usage: ./slowdown [--help] [baud] --help: Display this help message baud: The baud rate to emulate
Source code download: slowdown.c
Back to top
Simple TCP utilities
This is a set of command line utilities to work with TCP connections. Such as connecting to a server, accepting connections as a server, and forwarding connections between hosts.
There are three tools in the package:
- tcpserver Listens on a specified port on the local machine, and for each connection that is made to that port, spawns a process to handle the request using two pipes (6 and 7).
- tcpclient connects to the specified remote port, and spawns a client program to use the connection using two file descriptors for input/output.
- tcpforward Listens on a local port. For each connection that is made, forward it to the specified remote host and port. Forks a process for each child.