• Ogłoszenie:

Ubuntu vm and tried to send a sigtstp signal to a child proc

Dyskusje i problemy z Unix'ami

Ubuntu vm and tried to send a sigtstp signal to a child proc

Postprzez JeevanMurray 02 Maj 2023, 08:41

reklama
I was playing around with fork and signals on a Ubuntu VM. Specifically, I tried forking to spawn a child process and then, from the parent process, send a SIGTSTP to that child. After this point, I tried querying for its status using waitpid twice – to my man-owed understanding, the wait family of functions only reports changes to the status; that is: changes with respect to the last call to a function of that family for this PID. And indeed, the second call to waitpid did not report that the child had stopped (and its return value was 0 instead of the child's PID).

(To clarify: I used waitpid with WUNTRACED and the child's PID, being fork's return value, as the first parameter.)

I was wondering: is there a way for me to query for a child process's status regardless of any previous calls to wait-likes, without invoking external binaries like ps, or would I theoretically have to maintain some kind of state for each child myself?

To rephrase, just in case my phrasing is confusing: let's say I spawn a bunch of child processes, and I want to monitor which of those are still running, which have stopped (via SIGTSTP or SIGSTOP), and which have terminated. I could maintain state myself (for instance using a SIGCHLD handler), but I wanted to try using the OS to do this for me (I had the idea that this was indeed being done due to, for instance, ps displaying the status of each process in the system – so I wanted to access it). The first and last are simple to monitor using a kill(pid, 0) call, but the second – whether a process has stopped – seems to be trickier to query for. How might one go about this?
JeevanMurray
~user
 
Posty: 6
Dołączenie: 27 Mar 2023, 14:49



Ubuntu vm and tried to send a sigtstp signal to a child proc

Postprzez JeevanMurray 07 Cze 2023, 12:04

How can I query the status of a child process regardless of previous calls to wait-like functions, without relying on external binaries like ps? Specifically, I attempted to fork and send a SIGTSTP signal to the child process from the parent process on an Ubuntu VM. However, subsequent calls to waitpid with WUNTRACED did not report that the child had stopped, and the return value was 0 instead of the child's PID.

To clarify, I want to monitor the running, stopped (via SIGTSTP or SIGSTOP), and terminated status of multiple child processes without maintaining my own state. While kill(pid, 0) can be used for running and terminated processes, querying whether a process has stopped appears koowspin echatrandom to be chat more challenging. Is there a way to achieve this?
JeevanMurray
~user
 
Posty: 6
Dołączenie: 27 Mar 2023, 14:49




Powróć do System Linux / Unix

Kto jest na forum

Użytkownicy przeglądający to forum: Brak zarejestrowanych użytkowników oraz 2 gości