in reply to Signal handler - correct way to hijack TSTP
I've tried your code but it required a small change to run for me under perl v5.20.3. As it stands, the -t causes it grief:
[11541] START [02@21:54:27] Warning: Use of "-t" without parentheses i +s ambiguous at ./sigs.pl line 61. [11541] START [02@21:54:27] Use of ?PATTERN? without explicit operator + is deprecated at ./sigs.pl line 61. [11541] START [02@21:54:27] Search pattern not terminated or ternary o +perator parsed as search pattern at ./sigs.pl line 61. Leaving...
So changing line 61 to be this:
logger(INFO, sprintf("We %s connected to a TTY", -t () ? 'ARE' : 'ARE +NOT'));
It then runs and appears to handle the TSTP and subsequent CONT perfectly well. Which version of perl are you running and on which OS?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Signal handler - correct way to hijack TSTP
by seki (Monk) on Jan 11, 2021 at 11:07 UTC | |
Hi and thank you for your suggestion that I did missed. By testing the same code on 5.22.0 I encountered the same ambiguity warning as you. The code was initially written for a Perl 5.16.3 that runs on a Linux RHEL 6. By doing some more tests today, it seems that my problem was probably related to a mix of logs from different processes -a forgotten previous instance and a new one- in the same nohup.out i see different pids 258135 START 11@11:54:00 Setting up signal handlers 258135 RUN 11@11:54:00 Program PID 258135 has started 258135 RUN 11@11:54:00 We ARE NOT connected to a TTY 258135 In loop; sleeping... 257458 In loop; sleeping... 258135 RUN 11@11:54:02 SIGTSTP / CTRL-Z received. Suspending... 257458 In loop; sleeping... 257458 In loop; sleeping... Anyway i have improved my sscce by adding a proper propagation of the CONT signal to the childs. And I of course noticed that in case of a TERM to a child, it remains as a 'defunct' process until the parent terminates. I know about waitpid() that should fix that but am unsure of its correct use. Where to put it? here is my upgraded example:
The best programs are the ones written when the programmer is supposed to be working on something else. - Melinda Varian
| [reply] [d/l] |
by shmem (Chancellor) on Jan 11, 2021 at 11:52 UTC | |
I know about waitpid() that should fix that but am unsure of its correct use. Where to put it? Put that into the signal handler for $SIG{CHLD} in the parent. This is the signal a process gets if a subprocess goes away. See perlipc.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] [d/l] |
by seki (Monk) on Jan 11, 2021 at 19:27 UTC | |
Thank you, it is becoming actually satisfactory! htop helped much to test. My signal experimentation is now
The best programs are the ones written when the programmer is supposed to be working on something else. - Melinda Varian
| [reply] [d/l] |