When a program with some theards, mutexes, shared data, file handles crash because of too much memory allocation, which all resources are freed. How do you recover?
+1
A:
You recover by checking the results of resource acquisition functions and not allowing unchecked errors to occur in the first place.
Ignacio Vazquez-Abrams
2010-02-17 00:20:34
In the real world though, bugs happen.
leeeroy
2010-02-17 00:23:19
Try/catch on memory allocation can help you safely shut down though.Unless OOM killer gets you first.
Xorlev
2010-02-17 00:32:12
malloc never fails on Linux. Linux just kills the app when it tries to use the nonexistent memory. A try/catch will not help with this.
Justin Smith
2010-02-17 13:31:04
+1
A:
If you mean, how do you go back and free up the resources that were allocated by the now-crashed process, well, you don't have to.
When the process exit(2)'s or dies by a signal all of the OS-allocated resources will be retrieved. This is the kernel's job.
DigitalRoss
2010-02-17 00:23:16
But the process is not doing a clean exit- isnt that why the os did not release it in the first place?
Swapna
2010-02-17 05:32:49
It doesn't matter whether the exit occurs as a result of a system call or a signal, it will execute the same kernel code and do the same cleanup. That's the kernel's job and if it doesn't happen it's called a leak, it's about as serious as a kernel bug can be, and it's cause to withdraw a release, post security alerts, and generally launch into all kinds of emergency update hysteria.
DigitalRoss
2010-02-17 05:37:04