From nobody Wed Apr 16 19:46:40 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZdBNx1QBNz5t8nt; Wed, 16 Apr 2025 19:46:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZdBNw56N0z3lDS; Wed, 16 Apr 2025 19:46:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744832800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hLBGKVwa7uDZ4EbVA3nLJzkUFu1/dcXzrK9bpAfcjQU=; b=I5xtBh03ZngLY7LdXuHb6fWZCd99ea8TEhRuyDVbIEuHr4iqxbQZp34rVMGFoofhz+M+m1 M2YU450omz1qcX7DNjGeKTw49Lb1I67WlKld/n5VTs1fMh2kTgzk4rhv+MJ/UkRrkuy7yY I54EEzlEWSerM83h+cYxiQt5XbqDO9mC2Z6gCviatyid16Cz9WjS6HzlZUed+46SPAVi8m xEJNU2b7OWN/5zgJHv5Qgg/F1FpotmMrZkaXtTXP8EYDwP5VaSVzudwURktjoLelwE5sYD y4mMo3fyv92hxR+26NlQ2kg9E/TjrHm6gYUY6Arh0fQJTJOJElUu05MAMA3qKg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744832800; a=rsa-sha256; cv=none; b=NmiGGuauvX4ySXGqF+qH3pyy+nj318g06BANl6UxuXC1MGtp+QItj0v8TaRjKgmDrk5d0R YulliLOVwfOx+OB6VB5ZlFXnztHFtKHcTGbweIhpD9CB4o1oh9JurQBESYvue7HyDrR4Ns Z8OvUd/mlIbUYJ5wNT8/oUVQ+fN74fEJ41RPU7IkOX/0s9PRhqJQ+mclZYXb2o6MWpFYxf XWqKnDvpPWIy/N8h/O/dt0qs2RvUqGjBVSovHKGxlf9IX7e1/oVKU4VScYbirp0eb7lbAP RqmSuK7TiQIjMjqTsrghuJCOaiS2dBOWvAietdHfuMLqvH2oWn/A0qL6C5jDrg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744832800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hLBGKVwa7uDZ4EbVA3nLJzkUFu1/dcXzrK9bpAfcjQU=; b=wQh645RY0UsxfVPZlSLnLWqBh/Ym1OyFUQxya6Bd9MSbP/OzwjI8L6dZgEqfJX78BFDb8N h9tiVIgRFSx40iZs3KRbmDLRincotvHBsCQq7BN7PSKwhMkJLk3B1JILi9egTpeF2CpdTn Yl09WRhyo3nswz4Cf2/NFaAHw4pykybfVmvUkjj/BnvYL1gEAdSyp7YnoMKJo3Qt157pKN itVGyCWDCSv7C7/7ZB600cxGQsYkeWGYmHf/MQPf0I9vd6cWq+dy5bP2+64w+PokJoL49z 0vdIb+J3cHpW48vX6BatQSvXMGY2kEM418NdM9tG3ZdATrurn1jYOwUzCPWSkw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZdBNw4j2Mz1tJ; Wed, 16 Apr 2025 19:46:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53GJkeNi064031; Wed, 16 Apr 2025 19:46:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53GJkeqT064028; Wed, 16 Apr 2025 19:46:40 GMT (envelope-from git) Date: Wed, 16 Apr 2025 19:46:40 GMT Message-Id: <202504161946.53GJkeqT064028@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: c362781c8d6a - main - timeout(1): Document the reaper implementation and behaivor List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c362781c8d6a878ac93f3debc45d401bd5296eee Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=c362781c8d6a878ac93f3debc45d401bd5296eee commit c362781c8d6a878ac93f3debc45d401bd5296eee Author: Aaron LI AuthorDate: 2025-04-03 02:54:49 +0000 Commit: Baptiste Daroussin CommitDate: 2025-04-16 19:45:38 +0000 timeout(1): Document the reaper implementation and behaivor If timeout(1) runs with the --foreground option, it becomes the reaper of the command and its descendants and will wait for all of them to terminate. This behavior is different from the old FreeBSD version and GNU version. For example, if there is a descendant running in the background, like: $ timeout -s INT 2 sh -c 'sleep 4 & sleep 5' when timeout(1) sends the SIGINT to all descendants, the child 'sh' process and the foreground 'sleep 5' process will immediately terminate, but the background 'sleep 4' will be reparented to the timeout(1) itself. Because a background process ignores SIGINT and SIGQUIT, the whole command completes until the background 'sleep 4' finishes. In comparison, the old FreeBSD version and GNU version will just terminate itself, letting the background 'sleep 4' process be reparented to an upper reaper like init. The POSIX.1-2024 standard doesn't specify the required behavior in such cases, so I decided to keep the current implementation. Nonetheless, the updated timeout(1) has changed a lot in order to conform to the standard. Obtained-from: DragonFly BSD --- bin/timeout/timeout.1 | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/bin/timeout/timeout.1 b/bin/timeout/timeout.1 index 43a484dac76f..6486ccf99a36 100644 --- a/bin/timeout/timeout.1 +++ b/bin/timeout/timeout.1 @@ -1,6 +1,7 @@ .\" SPDX-License-Identifier: BSD-2-Clause .\" .\" Copyright (c) 2014 Baptiste Daroussin +.\" Copyright (c) 2025 Aaron LI .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -101,6 +102,9 @@ The options are as follows: Only time out the .Ar command itself, but do not propagate signals to its descendants. +See the +.Sx IMPLEMENTATION NOTES +section for more details. .It Fl k Ar time , Fl -kill-after Ar time Send a .Dv SIGKILL @@ -145,6 +149,30 @@ hours .It Cm d days .El +.Sh IMPLEMENTATION NOTES +If the +.Fl -foreground +option is not specified, +.Nm +runs as the reaper (see also +.Xr procctl 2 ) +of the +.Ar command +and its descendants, and will wait for all the descendants to terminate. +This behavior might cause surprises if there are descendants running +in the background, because they will ignore +.Dv SIGINT +and +.Dv SIGQUIT +signals. +For example, the following command that sends a +.Dv SIGTERM +signal will complete in 2 seconds: +.Dl $ timeout -s TERM 2 sh -c 'sleep 4 & sleep 5' +However, this command that sends a +.Dv SIGINT +signal will complete in 4 seconds: +.Dl $ timeout -s INT 2 sh -c 'sleep 4 & sleep 5' .Sh EXIT STATUS If the time limit was reached and the .Fl -preserve-status @@ -247,9 +275,9 @@ The command first appeared in .Fx 10.3 . .Pp -The +The initial .Fx -work is compatible with GNU +work was compatible with GNU .Nm by .An Padraig Brady , @@ -258,6 +286,7 @@ The .Nm utility first appeared in GNU Coreutils 7.0. .Sh AUTHORS -.An Baptiste Daroussin Aq Mt bapt@FreeBSD.org -and +.An Baptiste Daroussin Aq Mt bapt@FreeBSD.org , .An Vsevolod Stakhov Aq Mt vsevolod@FreeBSD.org +and +.An Aaron LI Aq Mt aly@aaronly.me