Skip to content

minor change from test_setup.sh "we have no reliable way to check if our parent is still alive" #14509

@chadm-sq

Description

@chadm-sq

Description of the problem / feature request:

tools/test/test-setup.sh has a comment and layers of workarounds for running a dependent "ps"-like program to test if a process exists. It claims that its convoluted fallbacks is because it can't test directly, but I think it can.

What operating system are you running Bazel on?

OSX.

Darwin 21.2.0 i386

Proposal

The magic 'kill' signal-spec of "0" means to test that a PID still exists and could receive a signal, without actually sending it a signal.

'kill' syscall man page says, "The kill() function sends the signal specified by sig to pid, a process or a group of processes. Typically, Sig will be one of the signals specified in sigaction(2). A value of 0, however, will cause error checking to be performed (with no signal being sent). This can be used to check the validity of pid."

And since "kill" is often a shell built-in, this has almost no cost on the OS, unlike spinning up a new process for "ps".

So, instead of the

while ps -p $$ &> /dev/null || [ "`pgrep -a -g $$ 2> /dev/null`" != "" ]; do

, it could be just while kill -0 $PPID &>/dev/null; do

(Contributing doc says to report bugs first instead of just submitting a PR. I'll make a PR too, if no one objects.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions