[Interest] QProcess when ^Z is called

Thiago Macieira thiago.macieira at intel.com
Fri Feb 11 02:58:19 CET 2022


On Thursday, 10 February 2022 16:41:48 PST Scott Bloom wrote:
> I have an issue, that if the customer hits Ctrl-Z after the executable is
> running, but has spawned a subprocess via QProcess, when the system is
> restarted (either in the background or foreground), the QProcess finished
> signal is lost.
> 
> Im assuming the OS level signal of sleep/wake cant be monitored while the
> application is a sleep.
> 
> Is there any known solution to this?

This goes into an area of process support I have yet to completely understand: 
controlling terminals, process groups and session leaders. Ctrl+Z indicates 
you're running from the shell, with job control active, which probably means 
your Qt process is the session leader. Ctrl+Z would have suspended all 
processes in the group. See:

$ (sleep 10s & read)
^Z
[1]  + 400272 suspended  ( sleep 10s & read; )
... wait more than 10 seconds ...
$ ps ft$TTY
    PID TTY      STAT   TIME COMMAND
  33201 pts/7    Ss     0:02 /bin/zsh
 400272 pts/7    T      0:00  \_ /bin/zsh
 400273 pts/7    T      0:00  |   \_ sleep 10s
 400338 pts/7    R+     0:00  \_ ps ft/dev/pts/7

That means the child process can't exit with just what you described, because 
the child is stopped alongside everything else in that process group. There's 
something more to your problem that you need to describe.

In any case, a dead child should become a zombie until the parent process 
performs the wait() call on it. This is what happens if you continue the 
child:

$ killall -CONT sleep
$ ps ft$TTY          
    PID TTY      STAT   TIME COMMAND
  33201 pts/7    Ss     0:02 /bin/zsh
 400394 pts/7    T      0:00  \_ /bin/zsh
 400395 pts/7    Z      0:00  |   \_ [sleep] <defunct>
 400412 pts/7    R+     0:00  \_ ps ft/dev/pts/7

The parent process will receive the SIGCHLD and QProcess will emit finished() 
when it resumes.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Interest mailing list