From: Ken Brown <kbrown@cornell.edu>
To: cygwin <cygwin@cygwin.com>
Subject: Synchronization problem with posix_spawn
Date: Wed, 29 Jul 2020 16:17:14 -0400 [thread overview]
Message-ID: <b1992e8b-d2e8-9c44-8f93-a270d5a879ed@cornell.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]
posix_spawn(p) returns before the spawned process is fully up and running. As a
result, the spawned process can fail to receive signals. The attached test case
illustrates the problem. It spawns a sleep process and then tries to kill it.
On exit, the sleep process is still running.
The following excerpts from the strace output show the issue: The SIGTERM signal
is sent after the main program has forked a subprocess (and posix_spawnp has
returned), but before the forked subprocess has exec'd the sleep process:
559 32069 [main] spawn_test 4125 vfork: stub called
257 48437 [main] spawn_test 4125 dofork: 4126 = fork()
754 9511 [main] spawn_test 4126 dofork: 0 = fork()
66 48503 [main] spawn_test 4125 kill0: kill (4126, 15)
44 9555 [main] spawn_test 4126 find_exec: find_exec (/usr/bin/sleep)
42 10835 [main] spawn_test 4126 spawnve: spawnve (/usr/bin/sleep, sleep,
0x8000281A0)
45 3149 [main] sleep 4126 child_info::ready: signalled 0x164 that I was ready
6475 21055 [main] spawn_test 4126! child_info::sync: pid 45028, WFMO
returned 0, exit_code 0x103, res 1
--- Process 45028 (pid: 4126) thread 41444 created
Ken
[-- Attachment #2: spawn_test.c --]
[-- Type: text/plain, Size: 469 bytes --]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <spawn.h>
#include <signal.h>
extern char **environ;
pid_t
run_sleep ()
{
pid_t pid;
char *argv[] = { "sleep", "3600", NULL };
int err = posix_spawnp (&pid, "/usr/bin/sleep", NULL, NULL, argv, environ);
if (err == 0)
return pid;
else
{
printf ("posix_spawnp: %s\n", strerror (err));
exit (1);
}
}
int
main ()
{
pid_t pid = run_sleep ();
kill (pid, SIGTERM);
}
next reply other threads:[~2020-07-29 20:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 20:17 Ken Brown [this message]
2020-07-29 23:12 ` Ken Brown
2020-07-30 11:59 ` Corinna Vinschen
2020-07-30 17:17 ` Corinna Vinschen
2020-07-30 23:04 ` Ken Brown
2020-07-31 8:10 ` Corinna Vinschen
2020-08-03 9:10 ` Peter Dons Tychsen
2020-08-03 10:50 ` Corinna Vinschen
2020-08-20 5:40 ` Peter Dons Tychsen
2020-08-20 12:50 ` Corinna Vinschen
2020-08-21 7:58 ` Peter Dons Tychsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b1992e8b-d2e8-9c44-8f93-a270d5a879ed@cornell.edu \
--to=kbrown@cornell.edu \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).