R359 Check a PID just before you send it a stopping signal

On by default

Just before you send a PID a signal that stops its process, check that the process under that PID is the one you mean to stop, and send the signal only when the check shows it is; when no process is under it, take that process as ended, and when another one is or the check cannot tell, send no signal and tell whoever delegated the work which process may be left running.

Reason

Once a process ends, the system can give its PID to another one: minutes after the process an agent means to stop has exited, the PID the agent holds can name a process someone else started, and a signal to it stops that one (Art. II §6(1)). Looking at the process under the PID just before the signal tells the two apart. A process can also change how it shows its command line, so a mismatch does not prove that the one meant has ended; whoever delegated the work then decides.

Verification

This holds for every process, whoever started it. The check reads, in the same command as the signal or in the one just before it, what identifies the process under the PID, such as its command line (ps -o args= -p <pid>, /proc/<pid>/cmdline) or its start time (ps -o lstart= -p <pid>), and compares it with what the agent knows of the process it means: for one it started, the command it started or the start time it recorded; for any other, what it saw when it looked at that process. The check has to tell the process meant from every other process: where two processes run the same command line, the command line alone does not tell them apart, and the agent compares a property that differs between them, such as the parent PID, the owner, the working directory or the start time; when nothing tells them apart, the check cannot tell. Stopping through a tool by the ID it gave, or by a name it resolves to the one process or container it manages, is not sending a signal to a PID and is outside this rule.

Violated when an agent sends a PID a signal that stops its process without such a check, or sends it when the check shows another process under the PID or cannot tell; or when, the check showing another process or unable to tell, it does not tell whoever delegated the work.

Provisions of the constitution it cites

Relations

Parent
R267 Shared Resources
Requires
none
Conflicts with
none

Metadata

ID
359
Revision
2
Kind
rule
Status
trial
Slug
check-a-pid-before-stopping
Default level
project
Constitution revisions
>=1
Check
none
Default
on
Uses
Instructions instructions
Original language
English en
Translations
Chinese zh