*** Welcome to piglix ***

Tsort (Unix)


The tsort program is a command line utility on Unix-like platforms, that performs a topological sort on its input.

According to its info page, this command was initially written for providing an ordering of object files that allowed the linker to process them sequentially (each one exactly once, and in order).

Note that the following description is describing the behaviour of the FreeBSD implementation of tsort and mentions GNU features where they may exist. Other implementations or versions may differ.

Options can be:

GNU provides the following options only:

tsort reads its input (from the given FILE, or standard input if no input file is given or for a FILE of '-') as pairs of strings, separated by blanks, indicating a partial ordering. The output is a total ordering that corresponds to the given partial ordering.

In other words: for a directed acyclic graph (used as a dependency graph), tsort produces a listing of the vertices so that for all edges 'a->b', 'a' comes before 'b' in the listing.

tsort lists the vertices of a directed acyclic graph in such an order that all ordering/direction relations are respected:

tsort can help rearranging functions in a source file so that as many as possible are defined before they are used (Interpret the following as: main() calls parse_options(), tail_file() and tail_forever(); tail_file() calls pretty_name(), and so on. The result is that dump_remainder() should be defined first, start_lines() second, etc.):

BSD UNIX uses tsort as a common part of the typical ar & ranlib command invocations (from /usr/share/mk/bsd.lib.mk):


...
Wikipedia

...