14

I am writing a tool which is written in python and C. The python script reads a configuration file, performs some validation makes several calls to the C program.

system: RHE 5.7, python: 2.7.6, gcc: 4.5.2

Some of the parameters to the called C program are the paths of input files. There is one case where the input file path is the same for several C program invocations. In this case only the first call succeeds, and the returncode from the python subprocess module is '-11'.

I am not sure how to progress this. For a start, I cannot find documentation indicating what '-11' might mean as an exit status. It does not appear to be in the 'standard' codes in /usr/include/sysexits.h. I am guessing that the code could also be interpreted as 0xf5 or 245, since exit codes are I believe really signed 8-bit values.

I have added debug to the start of the C program to print out the arguments it was called with, but nothing appears for the failed invocations. I can understand how the C might fail re-opening a file which was read on the previous invocation (perhaps), but the code doesn't even get that far!

So, where is the exit code coming from? Is it from the (bash) environment which the python subprocess module presumably uses to invoke the C program? Is it from the C runtime for the C program before it even reaches main?

I suppose I could progress this by moving the 'loop' down into the C, so that it only gets called once for each input file path, but that still does not explain this behaviour. Could someone please explain how I can determine the cause of this error? Thanks.

(FWIW) calling from python:

try:
  subprocess.check_call( args )
except subprocess.CalledProcessError as e:
  print e

Entry to the C:

printf( "\n--- swizzle\n\nargs:\n" );
for ( int i = 0; i < argc; i++ ) printf( "- %s\n", argv[ i ]);

Error output:

Command '[..]' returned non-zero exit status -11
PatB
  • 415
  • 1
  • 5
  • 13

1 Answers1

26

Return code -11 means "segmentation fault". A negative return code usually means that the process was terminated by a signal. Return code -11 means it was signal 11, which is SIGSEGV.

sth
  • 222,467
  • 53
  • 283
  • 367
  • 1
    Thanks. This indicates that the C program is running, crashing and failing to produce any debug output. Indeed, if I print the args out and always exit then the output appears for all invocations. This is simply a crash in the C. I think I have been working in python for so long I had grown to expect a full stack trace with every exception. – PatB Jun 10 '14 at 12:51
  • I had the same question and thanks for the answer. However, where is this negative exit code explained?? I was trying to search on Google but didn't find the document that explains this. – yaobin May 20 '16 at 16:57
  • 4
    @yaobin [Here](https://docs.python.org/3/library/subprocess.html#subprocess.Popen.returncode) `A negative value -N indicates that the child was terminated by signal N (POSIX only).` – YvesgereY Feb 20 '17 at 08:52
  • @YvesgereY Thanks for the link! – yaobin Feb 21 '17 at 15:10