Page MenuHomeFreeBSD

Teach ps(1) to select processes by parent process ID.

Authored by tmunro on Jul 30 2019, 11:49 PM.
Referenced Files
Unknown Object (File)
Sat, May 6, 1:50 AM
Unknown Object (File)
Mar 21 2023, 8:25 PM
Unknown Object (File)
Mar 4 2023, 12:22 AM


Group Reviewers

On Linux you can use ps --ppid for this. There is nothing in POSIX. I chose -P because it's not used in POSIX or Linux or well known BSDs, though unfortunately it means something different on Solaris so maybe it's a bad choice.

Diff Detail

rS FreeBSD src repository - subversion
Lint Skipped
Tests Skipped

Event Timeline

dteske requested changes to this revision.EditedJul 31 2019, 1:37 PM
dteske added a subscriber: dteske.

After thought, I support this change.

FreeBSD has never had this flag before, so we wouldn't be breaking anything. If someone were to try and run a Solaris script on BSD, they would have got an error about -P not being supported. Were it the case that we were repurposing -P, then there might be concern for issues, but adding a new flag that has never been there before ought to be safe.

This revision now requires changes to proceed.Jul 31 2019, 1:37 PM
This revision is now accepted and ready to land.Jul 31 2019, 6:27 PM

Perhaps it's better to convert ps to use getopt_long() so that we do not invent new single-letter options.

Also, filtering by ppid can be done with existing means, for example ps axl | awk -v ppid=1 'NR == 1 || $3 == ppid'

OK from manpages. Don't forget to bump the .Dd to the date of the commit. Thanks!

allanjude added a subscriber: allanjude.

Approved By: allanjude

Ok, based on feedback here and elsewhere, here's a version that uses getopt_long() from libc. It supports both --ppid (like Linux ps) and -P (like pgrep), and it seemed reasonable to add obvious long opts for --pid, --tty and --jail too. I decided not to try to add Linux-like --user, --User, --group, --Group in this patch (-u, -U, -g, -G all look a bit unportable and complicated). Thoughts?

This revision now requires review to proceed.Aug 2 2019, 11:35 AM
pstef added a subscriber: pstef.

I tested this and it works for me. The patch as a whole will look good to me when synopsis is updated to reflect the change.

This revision is now accepted and ready to land.Aug 15 2021, 7:00 PM