python - Why is this code behaving differently across various distros/Unixes? -


the following (a small c program , python script calls it) behave differently across various unixes.

in of them (e.g. debian stable), c app gets signal, message printed fine signal handler , script finishes. in others (e.g. 2 year-old ubuntu , openbsd) signal lost, , therefore message not printed @ all, , script waits forever...

the signal delivered, if in python script, change this...

mysub=subprocess.popen("./cryinabort", shell=true) 

into this...

mysub=subprocess.popen("./cryinabort", shell=false) 

so appears in unixes intermediate shell "eats" sigint, while in others forwards child process (the c program).

i took care call re-entrant functions in signal handler doesn't seem related c code - looks if signal handling behavior within "/bin/sh" (the default shell used python spawn things) not "stable" across unixes...

am doing wrong?

edit: in case wondering why used "shell=true": it's because in real code, not passing "./executable" - using shell code loops , wildcards.

this c code prints , dies when gets sigint:

#include <signal.h> #include <unistd.h>  void my_handler() {     static const char msg[] = "goodbye - test ok.\n";     write(1,msg,sizeof(msg));     fsync(1);     _exit (0); }  int main() {     (void) signal (sigint, my_handler);     while (1); } 

and python script tests sending sigint:

#!/usr/bin/env python import subprocess,signal,time mysub=subprocess.popen("./cryinabort", shell=true) time.sleep(2) mysub.send_signal(signal.sigint) mysub.wait() 

just because python uses /bin/sh doesn't mean it's same shell on systems.

/bin/sh alias in form of symbolic link: real shell busybox, bash, ash, csh, ksh, dash, zsh, tcsh, or crazy(er).

confirm you're using same shell on systems, if problem specific shell know more information on it's behavior.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -