Skip to content

linux/bsd/mac: Use pkill to stop remote instance over SSH #108412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wjt
Copy link
Contributor

@wjt wjt commented Jul 8, 2025

Previously, the PIDs of any running instances of the game on the remote device were found with pgrep, whose output was passed as parameters to kill. The problem with doing this is that passing zero arguments to kill (which happens when no instances of the game are running remotely) is an error: it shows the command usage, and exits with status 2 indicating a command-line syntax error:

$ kill
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
$ echo $?
2

As far as I can tell, all systems that have a pgrep command also have a pkill command which accepts (a superset of) the same parameters as pgrep and kills the matched processes instead of listing them on STDOUT.

In the case where no processes match, pkill exits with status 1; but does so silently.

Invoke pkill rather than pgrep + kill.

Previously, the PIDs of any running instances of the game on the remote
device were found with `pgrep`, whose output was passed as parameters to
`kill`. The problem with doing this is that passing zero arguments to
`kill` (which happens when no instances of the game are running
remotely) is an error: it shows the command usage, and exits with status
2 indicating a command-line syntax error:

    $ kill
    kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
    $ echo $?
    2

As far as I can tell, all systems that have a `pgrep` command also have
a `pkill` command which accepts (a superset of) the same parameters as
`pgrep` and kills the matched processes instead of listing them on
STDOUT.

In the case where no processes match, `pkill` exits with status 1; but
does so silently.

Invoke `pkill` rather than `pgrep` + `kill`.
@wjt wjt requested review from a team as code owners July 8, 2025 15:24
@Chaosus Chaosus added this to the 4.6 milestone Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants