[PATCH] ctdb-scripts: Invoke pstree with -l option (bug 13531)
Timur I. Bakeyev
timur at com.bat.ru
Wed Jul 18 19:51:46 UTC 2018
On 16 July 2018 at 14:27, Martin Schwenke via samba-technical <
samba-technical at lists.samba.org> wrote:
> Hi Amitay,
>
> On Mon, 16 Jul 2018 14:24:05 +1000, Amitay Isaacs
> <amitay at gmail.com> wrote:
>
> > On Sun, Jul 15, 2018 at 4:46 PM, Martin Schwenke via samba-technical
> > <samba-technical at lists.samba.org> wrote:
> > > This should get rid of the current flappiness in various CTDB tests
> that
> > > use the pstree command, most notably ctdb/tests/eventd/eventd_022.sh,
> > > which I've seen flapping quite a bit.
> > >
> > > As the commit message says, a couple of recent commits have lengthened
> > > the command string printed by pstree. This, in combination with the
> > > deep directory structure used by autobuild on sn-devel, is probably
> > > enough to take the test the flapping point. Then it probably comes
> > > down to the width of the PID printed in the original (unfiltered)
> > > pstree output. Wow! :-)
> > >
> > > ... and sorry about that... you never think about these things until
> > > they happen. Who knew that pstree truncates long lines? :-(
> > >
> > > I ran a private autobuild on sn-devel, running just the ctdb tests, in
> a
> > > loop this passed 9 times in a row (until I killed it).
> > >
> > > Please review and maybe push...
> >
> > NACK. Let's not make commands non-portable more than necessary.
>
> Hmmm... I thought that the version of pstree in, say, FreeBSD would be
> this one:
>
> http://www.pell.portland.or.us/~orc/Code/ps-etc/
>
> But it turns out that it is probably this one:
>
> https://www.freshports.org/sysutils/pstree
>
> where -l means something else entirely.
>
To your confusion stock `ps` in FreeBSD also cna give tree-like output with
-d option. for ex. `ps -daux`:
root 2488 0.0 0.2 37204 18000 - Ss Sun06 0:08.99 |--
/usr/local/sbin/nmbd --daemon --configfile=/usr/local/etc/smb4.conf
root 2492 0.0 1.8 173944 148808 - Is Sun06 0:07.99 |--
/usr/local/sbin/smbd --daemon --configfile=/usr/local/etc/smb4.conf
root 2503 0.0 1.3 130728 105264 - I Sun06 0:00.46 | |--
/usr/local/sbin/smbd --daemon --configfile=/usr/local/etc/smb4.conf
root 2504 0.0 1.3 130720 105120 - S Sun06 0:00.47 | `--
/usr/local/sbin/smbd --daemon --configfile=/usr/local/etc/smb4.conf
root 2497 0.0 0.7 86180 62480 - Ss Sun06 0:09.73 |--
/usr/local/sbin/winbindd --daemon --configfile=/usr/local/etc/smb4.conf
root 2502 0.0 0.3 45200 23328 - S Sun06 0:01.48 | |--
/usr/local/sbin/winbindd --daemon --configfile=/usr/local/etc/smb4.conf
root 2506 0.0 0.3 46180 23032 - S Sun06 0:00.67 | |--
/usr/local/sbin/winbindd --daemon --configfile=/usr/local/etc/smb4.conf
root 2507 0.0 0.3 47060 22692 - I Sun06 0:00.65 | `--
/usr/local/sbin/winbindd --daemon --configfile=/usr/local/etc/smb4.conf
> There is no real point in trying to match the output of pstree in
> > tests. We have two options.
> >
> > 1. Define PSTREE_CMD appropriately (this takes care of portability),
> > so we can match expected output.
> >
> > 2. Filter out pstree output before matching. Easier done in eventd
> > tests as we can just drop pstree command from debug-script.sh.
> >
> > We can pick 1 or 2, or some combination of 1 and 2.
>
> I wouldn't like to lose all of the pstree output. If for some reason
> something changes and the test fails then that output almost certainly
> provides enough information to understand why.
>
> Perhaps something like the following is good enough to show the event
> script and immediate children?
>
> $ ps -e -o pid,ppid,args | awk -v pid=$$ '$1 == pid || $2 == pid { print }'
> 9115 1642 bash
> 10487 9115 ps -e -o pid,ppid,args
> 10488 9115 awk -v pid=9115 $1 == pid || $2 == pid { print }
>
> I've used $$, which illustrates it well, but we would obviously use
> "$pid" or similar.
>
> As far as I can tell the above is completely POSIX-complaint.
>
We may consider to use `pgrep/pkill`, which does present on, at least,
FreeeBSD and Linux.
With regards,
Timur Bakeyev.
More information about the samba-technical
mailing list