Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil.Popen returns the wrong exit code when it is killed with a signal #960

Closed
delcypher opened this issue Jan 31, 2017 · 2 comments
Closed

Comments

@delcypher
Copy link

Summary

On Linux when a process gets killed by a signal the exit code is negative and the abs value of the exit code is the signal number (e.g. -6 is SIGABRT).

Python's subprocess.Popen will return the correct negative exit code if the application is killed with a signal. pustil.Popen does not.

I think this is bug because psutil.Popen is supposed to have the same interface as subprocess.Popen.

Either this is a bug which should be fixed or it is intentional behaviour. If it intentional is should really be documented.

I found this stackoverflow posted about this problem from a few years back but I'm not sure if the OP ever reported this problem.

http://stackoverflow.com/questions/25639578/psutil-subprocess-return-code-when-process-killed

How to reproduce

I did this use psutil==5.0.1 installed with pip.

Write a python program that aborts.

abort.py

import os
os.abort()

Now in an interactive python console try running it with subprocess.Popen

>>> import subprocess
>>> x = subprocess.Popen(['python', 'abort.py'])
>>> x.wait()
-6

Try running with psutil.Popen

>>> import psutil
>>> x = psutil.Popen(['python', 'abort.py'])
>>> x.wait()
6

You can see that the exit code from subprocess.Popen is negative indicating it was killed by a signal. psutil.Popen returns a positive exit code so it looks like the process was not killed by a signal even though it was!

@giampaolo
Copy link
Owner

This was indeed a bug. Fixed in 88e96ff.

delcypher pushed a commit to delcypher/klee-runner that referenced this issue Jan 31, 2017
@delcypher
Copy link
Author

@giampaolo Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants