Neale, I can't get it to compile at all. On most of my systems, I don't have a spawn.h file. On those that do, I get: /tmp/cc05Ni6H.o: In function `main': /tmp/cc05Ni6H.o(.text+0x1c): undefined reference to `posix_spawn_file_actions_init' /tmp/cc05Ni6H.o(.text+0x20): undefined reference to `posix_spawn_file_actions_adddup2' /tmp/cc05Ni6H.o(.text+0x28): undefined reference to `posix_spawnp' /tmp/cc05Ni6H.o(.text+0x3c): undefined reference to `posix_spawn_file_actions_destroy' collect2: ld returned 1 exit status
Sorry. Mark Post -----Original Message----- From: Ferguson, Neale [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 01, 2002 3:19 PM To: [EMAIL PROTECTED] Subject: posix_spawn & wait For those who are so inclined I'd be interested to see what you get when you compile and run the following "testspawn.c": #include <stdio.h> #include <spawn.h> int main(int argc, char **argv) { char *prog = "ls"; pid_t pid; int fdmap[3]; extern char **environ; int status; posix_spawn_file_actions_t pFaction; posix_spawn_file_actions_init(&pFaction); posix_spawn_file_actions_adddup2(&pFaction, 0, 0); posix_spawn_file_actions_adddup2(&pFaction, 1, 1); posix_spawn_file_actions_adddup2(&pFaction, 2, 2); if (posix_spawnp(&pid, prog, &pFaction, NULL, 0, environ) != -1) waitpid(pid, &status, 1); else perror("posix_spawn"); posix_spawn_file_actions_destroy(&pFaction); } I hang on the waitpid. However, if I invoke it using: strace ./testspawn. It completes without error. Same if I used gdb. If I change it to waitpid(pid, &status, 0); it also works properly. If you do it, please tell me: kernel level, glibc level, and distribution. When doing a comparison for fork/exec versus posix_spawn I see the later is about 10% more expensive. I must admit I preferred the semantics of the spawn() API as implemented in VM Open Extensions where the file_actions was a simple integer array. Neale
