Feat: Default PID
Make the pid parameter default to the PID of the current process. Change the exit code for invalid arguments to a value in the user defined range (see https://tldp.org/LDP/abs/html/exitcodes.html). This may be considered a breaking change, but since the only applications that currently use this script don't rely on this code, I don't think we need to bump the major version for this.
This commit is contained in:
parent
f2bdd47bec
commit
1516ff1550
11
rpid
11
rpid
@ -3,7 +3,8 @@
|
|||||||
USAGE='
|
USAGE='
|
||||||
USAGE: rpid <pid|-h|-[-]help> [<root_name>=login]
|
USAGE: rpid <pid|-h|-[-]help> [<root_name>=login]
|
||||||
|
|
||||||
pid The PID of the process for which you want to find the root PID.
|
pid The PID of the process for which you want to find the root
|
||||||
|
PID. Defaults to $$.
|
||||||
|
|
||||||
root_name
|
root_name
|
||||||
The name (not command line) of the root process, for which
|
The name (not command line) of the root process, for which
|
||||||
@ -20,16 +21,16 @@ EXAMPLES:
|
|||||||
Get the PID of the login process that is the ancestor of the current
|
Get the PID of the login process that is the ancestor of the current
|
||||||
process.
|
process.
|
||||||
|
|
||||||
rpid $$
|
rpid
|
||||||
'
|
'
|
||||||
|
|
||||||
# Validate the arguments
|
# Validate the arguments
|
||||||
if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then
|
if [[ "$#" -gt 2 ]]; then
|
||||||
printf '%s' "${USAGE}" 1>&2
|
printf '%s' "${USAGE}" 1>&2
|
||||||
exit 128
|
exit 64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pid="$1"
|
pid="${1:-$$}"
|
||||||
|
|
||||||
# Check if the user needs help
|
# Check if the user needs help
|
||||||
if [[ "${pid}" =~ ^(-h|-(-)?help)$ ]]; then
|
if [[ "${pid}" =~ ^(-h|-(-)?help)$ ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user