1174199Srwatson/*-
2174199Srwatson * Copyright (c) 2007 Robert N. M. Watson
3287486Sallanjude * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
4174199Srwatson * All rights reserved.
5174199Srwatson *
6174199Srwatson * Redistribution and use in source and binary forms, with or without
7174199Srwatson * modification, are permitted provided that the following conditions
8174199Srwatson * are met:
9174199Srwatson * 1. Redistributions of source code must retain the above copyright
10174199Srwatson *    notice, this list of conditions and the following disclaimer.
11174199Srwatson * 2. Redistributions in binary form must reproduce the above copyright
12174199Srwatson *    notice, this list of conditions and the following disclaimer in the
13174199Srwatson *    documentation and/or other materials provided with the distribution.
14174199Srwatson *
15174199Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16174199Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17174199Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18174199Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19174199Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20174199Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21174199Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22174199Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23174199Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24174199Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25174199Srwatson * SUCH DAMAGE.
26174199Srwatson *
27174199Srwatson * $FreeBSD: releng/11.0/usr.bin/procstat/procstat_basic.c 287486 2015-09-05 17:02:01Z allanjude $
28174199Srwatson */
29174199Srwatson
30186567Srwatson#include <sys/param.h>
31174199Srwatson#include <sys/sysctl.h>
32174199Srwatson#include <sys/user.h>
33174199Srwatson
34200462Sdelphij#include <err.h>
35221807Sstas#include <libprocstat.h>
36174199Srwatson#include <stdio.h>
37174199Srwatson#include <string.h>
38174199Srwatson
39174199Srwatson#include "procstat.h"
40174199Srwatson
41174199Srwatsonvoid
42221807Sstasprocstat_basic(struct kinfo_proc *kipp)
43174199Srwatson{
44174199Srwatson
45174199Srwatson	if (!hflag)
46287486Sallanjude		xo_emit("{T:/%5s %5s %5s %5s %5s %3s %-8s %-9s %-13s %-12s}\n",
47174199Srwatson		    "PID", "PPID", "PGID", "SID", "TSID", "THR", "LOGIN",
48174199Srwatson		    "WCHAN", "EMUL", "COMM");
49174199Srwatson
50287486Sallanjude	xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
51287486Sallanjude	xo_emit("{:parent_process_id/%5d/%d} ", kipp->ki_ppid);
52287486Sallanjude	xo_emit("{:process_group_id/%5d/%d} ", kipp->ki_pgid);
53287486Sallanjude	xo_emit("{:session_id/%5d/%d} ", kipp->ki_sid);
54287486Sallanjude	xo_emit("{:terminal_session_id/%5d/%d} ", kipp->ki_tsid);
55287486Sallanjude	xo_emit("{:threads/%3d/%d} ", kipp->ki_numthreads);
56287486Sallanjude	xo_emit("{:login/%-8s/%s} ", strlen(kipp->ki_login) ?
57287486Sallanjude	    kipp->ki_login : "-");
58174199Srwatson	if (kipp->ki_kiflag & KI_LOCKBLOCK) {
59287486Sallanjude		xo_emit("{:lockname/*%-8s/%s} ", strlen(kipp->ki_lockname) ?
60174199Srwatson		    kipp->ki_lockname : "-");
61174199Srwatson	} else {
62287486Sallanjude		xo_emit("{:wait_channel/%-9s/%s} ", strlen(kipp->ki_wmesg) ?
63174199Srwatson		    kipp->ki_wmesg : "-");
64174199Srwatson	}
65287486Sallanjude	xo_emit("{:emulation/%-13s/%s} ", strcmp(kipp->ki_emul, "null") ?
66287486Sallanjude	    kipp->ki_emul : "-");
67287486Sallanjude	xo_emit("{:command/%-12s/%s}\n", kipp->ki_comm);
68174199Srwatson}
69