From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C78B41FF0A5 for ; Thu, 19 Nov 2026 15:50:50 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4249E21714; Thu, 19 Nov 2026 15:50:49 +0100 (CET) From: Jordyn Hamilton To: pve-devel@lists.proxmox.com Subject: [PATCH common 1/2] Added subroutine to check process status Date: Thu, 19 Nov 2026 09:50:10 -0500 Message-ID: <20261119145011.8017-2-j.hamilton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119145011.8017-1-j.hamilton@proxmox.com> References: <20261119145011.8017-1-j.hamilton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795099844961 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.109 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: XYT5VPWOMXN7YAYSF5IF5NENS6XT4ZJ7 X-Message-ID-Hash: XYT5VPWOMXN7YAYSF5IF5NENS6XT4ZJ7 X-MailFrom: j.hamilton@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: j.hamilton@proxmox.com, c.hughes@proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Added a subroutine to check if a process is in a D state. It does so by reading the processes `stat` file from `/proc/$pid/stat`, then using regex to grab a group containing the status character. It then returns true or false if the status is 'D'. Not checking for any other status types as D state is the only one that needs special logic. Signed-off-by: Jordyn Hamilton --- src/PVE/Cmd.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/PVE/Cmd.pm b/src/PVE/Cmd.pm index 65d00a7..773e55a 100644 --- a/src/PVE/Cmd.pm +++ b/src/PVE/Cmd.pm @@ -44,6 +44,18 @@ sub split_args($str) { return $str ? [Text::ParseWords::shellwords($str)] : []; } +# check a subprocesses `/proc//stat` file for a D state +sub in_d_state($pid) { + open my $pstat_h, '<', "/proc/$pid/stat" or die $!; + my $stat_in = <$pstat_h>; + close $pstat_h; + + # extracting the stat character from the input + my $status = $1 if $stat_in =~ /^\d+\s+\(.*\)\s+([A-Z])/; + + return ($status eq 'D'); +} + # The $cmd parameter can be: # -) a string # This is generally executed by passing it to the shell with the -c option. -- 2.47.3