Tsort
≈ 3 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
The tsort program is a command line utility on Unix and Unix-like platforms, that performs a topological sort on its input. It is part of the POSIX.1 standard. and has been since The Single UNIX Specification, Version 2.
The tsort program is a command line utility on Unix and Unix-like platforms, that performs a topological sort on its input. It is part of the POSIX.1 standard. and has been since The Single UNIX Specification, Version 2. ==History== 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). The FreeBSD manual page dates its appearance to Version 7 Unix. Note that the following description is describing the behavior of the FreeBSD implementation of tsort and mentions GNU features where they may exist. Other implementations or versions may differ. ==Syntax== tsort [-dlq] [FILE] FreeBSD options can be: -d turn on debugging -l search for and display the longest cycle. -q Do not display informational messages about cycles. GNU provides the following options only: --help display help message and exit --version display version information and exit There are no options prescribed by POSIX. ==Behavior== 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. ==Examples== tsort lists the vertices of a directed acyclic graph in such an order that all ordering/direction relations are respected: lib${LIB}.a: ${OBJS} ${STATICOBJS} @${ECHO} building static ${LIB} library @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} ${RANLIB} ${.TARGET} Here ("library order") is used to generate the inter-file dependency list by inspecting the symbol table. ==Usage notes== Notice the interchangeability of white space separators so the following inputs are equivalent: Pairs of identical items indicate presence of a vertex, but not ordering (so the following represents one vertex without edges): a a Strictly speaking there is no topological ordering of a graph that contains one or more cycles. However tsort prints a warning and GNU tsort prints the detected cycles to standard error (lines beginning with 'tsort:'): $ tsort a b > b c > c a > EOF UX: tsort: INFORM: cycle in data tsort: a tsort: b tsort: c a b c ==See also== Sort (Unix) Make (software) Topological sorting List of Unix commands Call graph ==POSIX== From 1997 until 2024, the POSIX version of the tsort program accepted no arguments other than an optional file name containing the input data (it reads from standard input if no file is specified). With the 2024 version, POSIX specifies an optional -w argument that reports on the number of loops found in the exit status of the command. ==References== ===Further reading=== ==External links== manual page of tsort on FreeBSD, OpenBSD, NetBSD , AIX, Solaris, HP-UX dep-trace Orders basic dependencies and unfolds nested ones. (basic: without 2D graphical presumption)
Text derived from https://en.wikipedia.org/w/index.php?oldid=1353544942 under CC BY-SA 4.0; modifications have been made.