Page MenuHomeFreeBSD

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

Authored by tmunro on Jul 30 2019, 11:49 PM.

Details

Reviewers
dteske
allanjude
Group Reviewers
manpages
Summary

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

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

tmunro created this revision.Jul 30 2019, 11:49 PM
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
dteske accepted this revision.Jul 31 2019, 6:27 PM
This revision is now accepted and ready to land.Jul 31 2019, 6:27 PM
jilles added a subscriber: jilles.Jul 31 2019, 7:14 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'

bcr added a subscriber: bcr.Aug 1 2019, 2:43 PM

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

allanjude accepted this revision.Aug 1 2019, 4:26 PM
allanjude added a subscriber: allanjude.

Approved By: allanjude

tmunro updated this revision to Diff 60383.EditedAug 2 2019, 11:35 AM

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