<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="list-process-table">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>list-process-table</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">administrator commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>list-process-table</refname>
<refpurpose>process listing tool</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>list-process-table</command>
<arg choice="opt">--field <replaceable>name</replaceable></arg>
<arg choice="opt">--threads</arg>
<arg choice='opt'>--tui-level <replaceable>level</replaceable></arg>
<arg choice="opt">--time-format <replaceable>formatstring</replaceable></arg>
<arg choice="opt" repeat="rep"><replaceable>PIDs</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>list-process-table</command> is a tool for listing process information.
Its output is machine-parseable and suitable for <citerefentry><refentrytitle>console-flat-table-viewer</refentrytitle><manvolnum>1</manvolnum></citerefentry> with 1 header line and <arg choice='plain'>--format tabbed</arg> or <citerefentry><refentrytitle>awk</refentrytitle><manvolnum>1</manvolnum></citerefentry> with <arg choice='plain'>-F'\t'</arg>.
</para>

<para>
It has a much simpler interface than the <citerefentry><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry> command.
In fact that latter command (in this toolset) is a shim around <command>list-process-table</command>, turning its more complex interface into a plain list of output field names and processs IDs.
</para>

<para>
The <arg choice="plain"><replaceable>PID</replaceable></arg> command-line arguments are a filter set that is matched against the process IDs, enabling the selection of individual process records.
If there are no <arg choice="plain"><replaceable>PID</replaceable></arg> arguments, the entire list is output, unfiltered.
It is not an error for a filter item not to match a process ID.
</para>

<para>
The <arg choice="plain">--threads</arg> command-line option controls whether <command>list-process-table</command> asks the operating system for a list of all individual threads, or simply all processes.
</para>

<para>
The <arg choice="plain">--field</arg> command-line option specifies a list of fields by <arg choice="plain"><replaceable>name</replaceable></arg>.
What exactly the fields are varies from operating system to operating system.
There is a basic common set:
<arg choice="plain">pid</arg>,
<arg choice="plain">ppid</arg>,
<arg choice="plain">pgid</arg>,
<arg choice="plain">flags</arg>,
<arg choice="plain">state</arg>,
<arg choice="plain">uid</arg>,
<arg choice="plain">sid</arg>,
<arg choice="plain">pcpu</arg>,
<arg choice="plain">pri</arg>,
<arg choice="plain">nice</arg>,
<arg choice="plain">vsz</arg>,
<arg choice="plain">rss</arg>,
<arg choice="plain">wchan</arg>,
<arg choice="plain">stime</arg>,
<arg choice="plain">tty</arg>,
<arg choice="plain">time</arg>,
<arg choice="plain">comm</arg>,
<arg choice="plain">args</arg>,
<arg choice="plain">envs</arg>, and
<arg choice="plain">tree</arg>.
</para>

<para>
The <arg choice="plain">--time-format</arg> command-line option specifies an alternative display format to be employed for all time fields, <arg choice="plain"><replaceable>formatstring</replaceable></arg>, in the form employed by the <citerefentry><refentrytitle>strftime</refentrytitle><manvolnum>3</manvolnum></citerefentry> library function.
</para>
<note>
Linux pre-formats several time fields into human-readable form itself, and this option has no effect upon such fields.
</note>

</refsection>

<refsection><title>Output</title>

<para>
The output format is variable-length records terminated by LF containing TAB-separated fields.
Fields are output as if passed through the BSD <citerefentry><refentrytitle><code>vis</code></refentrytitle><manvolnum>3</manvolnum></citerefentry> library function.
They are thus unambiguously machine-parseable, because any whitespace in the field itself is encoded by <citerefentry><refentrytitle><code>vis</code></refentrytitle><manvolnum>3</manvolnum></citerefentry>.
After separating out an individual field, its contents can (for example) be decoded in shell script using the <citerefentry><refentrytitle><code>unvis</code></refentrytitle><manvolnum>1</manvolnum></citerefentry> utility (which is supplied by FreeBSD).
</para>

<para>
The <arg choice="plain">args</arg> field has light shell quoting applied before being <citerefentry><refentrytitle><code>vis</code></refentrytitle><manvolnum>3</manvolnum></citerefentry>-encoded.
This quoting is weighted towards encapsulating whole arguments, where quoting is needed, as one whole quoted string; and does not produce things that a conformant <citerefentry><refentrytitle><code>sh</code></refentrytitle><manvolnum>1</manvolnum></citerefentry> could misinterpret as variable assignments.
After decoding with <citerefentry><refentrytitle><code>unvis</code></refentrytitle><manvolnum>3</manvolnum></citerefentry> or similar, it is thus in a form usable by a shell.
</para>

<para>
The <arg choice="plain">envs</arg> field has different quoting applied before being <citerefentry><refentrytitle><code>vis</code></refentrytitle><manvolnum>3</manvolnum></citerefentry>-encoded.
This quoting prefers unquoted forms more than the light shell quoting does, at the expense of more quote and escape characters.
After decoding with <citerefentry><refentrytitle><code>unvis</code></refentrytitle><manvolnum>3</manvolnum></citerefentry> or similar, it is in a form usable by <citerefentry><refentrytitle><code>read-conf</code></refentrytitle><manvolnum>1</manvolnum></citerefentry> and similar utilities.
</para>

<para>
The <arg choice="plain">tree</arg> field is calculated from the process ID and parent process ID information in the process table.
Output records are always sorted into tree-display order (in ascending order of process ID for the children beneath any given parent) whether or not the field is actually selected for output.
Selection of records by process ID happens after the tree has been generated, and may cause the tree to look odd.
</para>

<para>
The <arg choice='plain'>--tui-level</arg> command-line option constrains the use of MouseText or Unicode block graphics and line drawing characters in the <arg choice="plain">tree</arg> field.
</para>

<refsection><title>Header row</title>

<para>
The field names are transformed to uppercase for the initial header record.
For compatibility with traditional tools, per the Single Unix Specification several field names are altered into different names for the header names.
In addition to the list of such replacements that is documented in the Single Unix Specification in the section for the <command>ps</command> utility:
</para>
<itemizedlist>
<listitem><para>
The <arg choice="plain">flags</arg>, <arg choice="plain">state</arg>, <arg choice="plain">address</arg>, and <arg choice="plain">size</arg> field names are replaced by <code>F</code>, <code>S</code>, <code>ADDR</code>, and <code>SZ</code>.
This is implied by but not actually stated in the Single Unix Specification.
</para></listitem>
<listitem><para>
The <arg choice="plain">logname</arg> field name is replaced by <code>LOGIN</code>.
This is not a field defined by the Single Unix Specification, but is part of the information available about a process on FreeBSD.
Its replacement is in line with the FreeBSD <citerefentry><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry> command.
</para></listitem>
<listitem><para>
The <arg choice="plain">comm</arg> field name is replaced by <code>COMM</code>.
This is a deviation from the Single Unix Specification and the FreeBSD <citerefentry><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry> command.
It agrees, rather, with Laurent Berot's <command>s6-ps</command>.
</para><para>
It eliminates confusion with the <code>COMMAND</code> field heading that the Single Unix Specification engenders, albeit that the Single Unix Specification's <arg choice="plain">comm</arg> field is not what real <command>ps</command> tools on Linux and the BSDs actually do.
<arg choice="plain">comm</arg> is supposed to be just the first string in <arg choice="plain">args</arg> according to the Single Unix Specification.
Hence why <code>COMMAND</code> can be the header for both fields.
Actual <command>ps</command> commands on Linux and the BSDs instead display an "accounting name" for the process in this field, and not its argument strings at all.
</para></listitem>
</itemizedlist>

</refsection>

</refsection>

<refsection><title>Race conditions</title>

<para>
There is an unavoidable race condition, on both FreeBSD with its <citerefentry><refentrytitle><code>sysctl</code></refentrytitle><manvolnum>3</manvolnum></citerefentry> API and Linux with its lots-of-pseudo-files API, between reading the main information for a process from the process table and reading its argument and environment strings.
There is a window between the two within which a process may terminate and be reaped from the process table, resulting in argument and environment strings not being read, and their columns in the resultant output being empty.
</para>

</refsection>

<refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
