6

I've compiled small C++ application for school project on my virtual ubuntu 11.04. However when I attempt to run it over some larger data set after ~20 sec the program is killed by OS.

Killed (SIGKILL)

I need to find out why and remove the problem. Could it be that I've not enough memory to run the program? Note: I need to find data set large enough to make it run for several minutes.

viktor
  • 163
  • 1
  • 1
  • 5
  • Strange, when you request resources like memory or IO operation, the OS will say "OK" or "not OK", but killing the process seems a little drastic. What could have happened is that you were killed because you performed an invalid operation (accessing memory you can't access). Do you have BUS ERROR/Segmentation Fault errors? Run your program within gdb (gdb ./program and hit 'r [arg1] [arg2] to run it), provide us with the output. – Aki Feb 08 '12 at 18:26
  • How large is large? Also, what `ulimit`s is it running under? Type `ulimit` on the same console you're running your program from to see if the environment is severely limiting some resource you might need (e.g. memory, CPU time, etc). – Alexios Feb 08 '12 at 18:32
  • 1
    Can you share the code? Or at least the part of the code where it happens (you can build it with debug information and run it under some debugger like `gdb` — when it gets killed, you should be able to get a backtrace (although I'm not sure about how `gdb` handles `SIGKILL`, I know `SIGSEGV` can be trapped by `gdb`, now `SIGKILL` I don't know.) – njsg Feb 08 '12 at 18:38
  • 3
    Also check `dmesg`, might be some info there. – Mat Feb 08 '12 at 18:44
  • gdb just prints `Program terminated with signal SIGKILL, Killed. The program no longer exists` When I use smaller input data set, the program works fine. – viktor Feb 08 '12 at 19:04
  • It seems there is not enough memory for such data set dmsg: Out of memory: kill process 1666 (gnome-session) score 221113 or a child – viktor Feb 08 '12 at 19:05
  • 2
    @aki - Often resources are allocated on the assumption that they will be available when required. Many OSes overallocate on this assumption. – Chris Down Feb 08 '12 at 19:39
  • I've found one memory leak in the code using valgrind. Now it works much better. – viktor Feb 08 '12 at 20:24
  • @ChrisDown: indeed, I forgot that Linux overcommits memory. – Aki Feb 08 '12 at 21:44

1 Answers1

6

It's probably killed by kernel's oom killer. dmesg should contain information about it. Sorry, but you may need to redesign your algorithm.

rvs
  • 1,633
  • 13
  • 13
  • Would the OOM killer kill this application? Isn't it designed to select a program with a half-random algorithm and kill it? ahh.. I really despise the OOM killer, I understand why it's needed though... Wish one could build a linux kernel with a -DLOGICAL_BEHAVIOR flag :). – Aki Feb 08 '12 at 21:47
  • 1
    It tries to kill most memory-hungry application. In some cases (due to memory sharing) it can kill wrong application, but most of the time it does the right thing. – rvs Feb 09 '12 at 06:10
  • Oh it evolved well since the time it used to kill sshd. – Aki Feb 09 '12 at 06:12
  • You can disable the OOM killer if you really like to. But then you are no longer able to over-allocate memory. – Nils Feb 09 '12 at 21:46