1 # Copyright (c) 2010 Nicira Networks
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 def _signal_status_msg(type, signr):
19 s = "%s by signal %d" % (type, signr)
20 for name in signal.__dict__:
21 if name.startswith("SIG") and signal.__dict__[name] == signr:
22 return "%s (%s)" % (s, name)
25 def status_msg(status):
26 """Given 'status', which is a process status in the form reported by
27 waitpid(2) and returned by process_status(), returns a string describing
28 how the process terminated."""
29 if os.WIFEXITED(status):
30 s = "exit status %d" % os.WEXITSTATUS(status)
31 elif os.WIFSIGNALED(status):
32 s = _signal_status_msg("killed", os.WTERMSIG(status))
33 elif os.WIFSTOPPED(status):
34 s = _signal_status_msg("stopped", os.WSTOPSIG(status))
36 s = "terminated abnormally (%x)" % status
37 if os.WCOREDUMP(status):