  [% META title = 'Resources &raquo; Process Status' meta_refresh = 60 -%]

<!-- BEGIN [% template.name %] -->
	[% # PROCESS dumper.tt dump = data %]

	<h3>Process status [[% cmd %]]</h3>

	[%
		cfg = c.cfg('settings');
		is_sysadmin = ( cfg.item('_centre') == cfg.sysadmin_centre ) ? 1 : 0;

		headers = [ 'user' 'pid' 'cpu' 'rss (KB)' 'vmem (KB)' 'start' 'time' 'process' ];
		headers.push('kill') IF is_sysadmin;
	%]

    [% BLOCK tbl_row %]
		<tr class="[% class %]">
            <td>[% process.user %]</td>
			<td>[% process.pid %]</td>
			<td>[% process.cpu %]</td>
			<td align="right">[% process.rss; '|'; process.percent; '%' %]</td>
			<td align="right">[% process.vmem %]</td>
			<td>[% process.start %]</td>
			<td>[% process.time %]</td>
			<td>[% centre.upper; '|'; process.type %]</td>
			<td>
			[% IF is_sysadmin AND NOT process.type.match('parent') %]
				<input type="radio" name="pid" value="[% process.pid %]" />
			[% ELSE; '<span class="white">--</span>'; END %]
			</td>
		</tr>
    [% END %]

	<form action="[% c.query.self_url %]" method="post">
		<table class="indent">
			<tr>
				[% FOREACH h IN headers %]
				<th>[% h %]</th>
				[% END %]
			</tr>
			[% FOREACH href IN data.pairs;
				centre = href.key;
				rows   = href.value; # hashref
				FOREACH process IN rows;
                    NEXT UNLESS process.type.match('parent'); # parent 1st
                    INCLUDE tbl_row class = 'grey';
                END;
				FOREACH process IN rows; # hashref
                    NEXT IF process.type.match('parent');
                    INCLUDE tbl_row class = 'normal';
                END;
			END %]
			<tr class="borderless">
				<td colspan="3">
					[% site.html.back_button %]
					<input type='submit' value='Refresh' name='.submit' class='button' />
				</td>
                <td colspan="4">
                    <span class="grey">[seconds until auto refresh:
                        <span id="refresh"></span>]</span>
                </td>
				<td colspan="4" align="right">
					[% IF is_sysadmin %]
						<span class="bold">kill selected:</span>
						<input type='submit' value='Go' name='.submit' class='button' />
					[% END %]
				</td>
			</tr>
		</table>
    </form>

	<h4>Definitions (man ps):</h4>
	<dl>
		<dt>%cpu</dt>
		<dd>cpu utilization of the process in "##.#" format.
			Currently, it is the CPU time used divided by the time the
			process has been running (cputime/realtime ratio),
			expressed as a percentage. It will not add up to 100%
			unless you are lucky.</dd>
		<dt>%mem</dt>
		<dd>ratio of the process's resident set size  to the physical
			memory on the machine, expressed as a percentage.</dd>
		<dt>vsv</dt>
		<dd>virtual memory size of the process in KiB
			1024-byte units). Device mappings are currently excluded;
			this is subject to change.</dd>
		<dt>rss</dt>
		<dd>resident set size, the non-swapped physical memory that a
			task has used (in kiloBytes).</dd>
		<dt>vsz</dt>
		<dd>virtual memory size. It includes all memory that the process can access,
			including memory that is swapped out and memory that is from shared
			libraries.
		</dd>
		<dt>start</dt>
		<dd>time the command started. If the process was started less
			than 24 hours ago, the output format is "HH:MM:SS", else
			it is "  mmm dd" (where mmm is a three-letter month name).</dd>
		<dt>time</dt>
		<dd>cumulative CPU time, "[dd-]hh:mm:ss" format.</dd>
	</dl>
<!-- END [% template.name %] -->
