Main Page

From SxStdio

Welcome to sx-stdio homepage.


What is sx-stdio?

Sx-stdio stands for Structured Extensible Standard I/O.

sx-stdio is a specification and a toolkit to allow structured input and output for POSIX programs.

It also contains wrappers for common UNIX commands that use this (above) library to eliminate the need for text parsing when integrating these commands using shell pipes.

The idea is to create a specification of how programs will receive input and provide output. The spec will make sure the input and output data will be structured so no parsing will be required when piping this output as input for other programs.

The project will consist of two efforts: (1) designing the specification and implementing a toolkit (a shared library, shell utilities, python scripts) and (2) implementing wrappers to common UNIX utilities so that they will receive their input using this spec and provide their output using this spec.



For example:

Lets say we wish to kill all the parent-process of all the processes that the words 'usr' are in their command line.

Currently, we will have to execute the following commands:

1. Execute the following command to get all the processes with the word 'usr' in their command line.

ps -f | grep usr

2. Since 'cut' can't be used directly to cut the PPID column (the 3rd), because there is more than one space between some of the columns.

3. There are many ways to extract the time column. I would use:

.. | sed ":start;s/  / /;t start" | cut -d' ' -f3

4. Now, we need to serve these PIDs to kill using xargs:

.. | xargs kill -s kill

So the final command will look like this:

ps -f | grep "usr" | sed ":start;s/  / /;t start" | cut -d' ' -f3 | xargs kill -s kill

Using our commands, the same command will look like that:

ps -f | grep "usr" | select "ppid=>pid" | kill -s kill

Explanation: The first two commands are the same. "select" chooses which columns from the output of ps to pass along the pipe. The "=>" is used to rename the column named 'PPID' to 'PID' (since kill uses the PID as the input column for which processes to kill).

Now lets say we wish to run the same command but now select only processes that run for more than 30 minutes. With today's stdio, it would be almost impossible to do without a mini-script. With sx-stdio, we can use the 'where' command to do a "smart" grep:

ps -f | grep "usr" | where "running-time > 30min" | select "ppid => pid" | kill -s kill

"where" will grep the rows from the output of 'ps' such that only rows that their 'running-time' column contains a number that's larger than 30 minutes will be passed through the pipe to the next command (in this case, "select").