I have a global cgroup defined in /etc/cgconfig.conf
that limits the amount of memory. Everytime a user runs a command, I prepend cgexec
to add the process and its children to the controlled group. Every now and then the limit kicks in and kills the user process.
If the exit code is not 0
, how do I know if the process just failed because of some internal logic, or if it has been killed by the cgroup mechanism?
It's running in user space, so I'd like to avoid parsing /var/log/syslog
.
/var/log/kern.log
will tell you that. In this case it logs death of a process running inside docker's cgroups which are inside LXC's cgroups.I have conducted a series of experiments to answer the same question you have a few years ago, and my experiments showed that the killed process always has exit code 137 (which is 128 + 9, where 128 is the POSIX requirement for terminated executions and 9 is the integer code of SIGKILL [kill signal]). Unfortunately, I couldn't find a way to confirm that it was indeed a SIGKILL and not just the user-reported exit code
exit(137)
/return 137;