Subject: Re: proposal for new ps(1) option -H
To: None <tech-userlevel@netbsd.org>
From: Jan Kryl <loo@bazmek.net>
List: tech-userlevel
Date: 09/07/2007 09:55:25
--gBBFr7Ir9EOA20Yy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On 07/09/07 01:06 +0200, Alan Barrett wrote:
> If -o and -s options worked nicely together, it would be
>
> $ ps -axs -o pid,lid,command
>
> I'd prefer to work on making "-o" play nicely with "-s" rather than
> adding a "-H" option. My idea is: if you use "-s" without explicitly
> selecting a set of columns, then it works as at present; if you
> explicitly select a set of columns with "-o", then that overrides the
> default columns that "-s" would otherwise have selected; and if you use
> "-O" then it augments the set of columns that "-s" selected.
>
Sounds good to me. If I understand you correctly, you propose to change
default output format of ps(1) in case we are in "one line for LWP" mode.
I have attached trivial patch, which does exactly this. There's one
disadvantage of my patch - the order of -O and -s arguments matters. The
following commands produce different output:
ps -axsO nice (this is probably what you wanted)
ps -axO nice -s (now you get maybe frustrated ...)
But the same holds currently for combination of -O and -u,-l,-v options,
so I guess nobody would complain about it.
Cheers,
Jan
--gBBFr7Ir9EOA20Yy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="modified-s.patch"
Index: ps.c
===================================================================
RCS file: /home/loo/cvsup/src/bin/ps/ps.c,v
retrieving revision 1.63
diff -u -r1.63 ps.c
--- ps.c 17 Feb 2007 22:49:57 -0000 1.63
+++ ps.c 7 Sep 2007 07:20:22 -0000
@@ -239,7 +239,7 @@
*/
if (!Opos) {
if (!fmt)
- parsefmt(dfmt);
+ parsefmt(showlwps ? sfmt : dfmt);
Opos = varlist_find(&displaylist, "pid");
}
parsefmt_insert(optarg, &Opos);
@@ -263,9 +263,6 @@
case 's':
/* -L was already taken... */
showlwps = 1;
- parsefmt(sfmt);
- fmt = 1;
- sfmt[0] = '\0';
break;
case 'T':
if ((ttname = ttyname(STDIN_FILENO)) == NULL)
@@ -373,7 +370,7 @@
errx(1, "%s", errbuf);
if (!fmt)
- parsefmt(dfmt);
+ parsefmt(showlwps ? sfmt : dfmt);
/* Add default sort criteria */
parsesort("tdev,pid");
--gBBFr7Ir9EOA20Yy--