Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most violent way that an application can terminate itself (linux)

I'd like to emulate violent system shutdown, i.e. to get as close as possible to power outage on an application level. We are talking about c/c++ application on Linux. I need the application to terminate itself.

Currently i see several options:

  1. call exit()
  2. call _exit()
  3. call abort()
  4. do division by zero or dereference NULL.
  5. other options?

What is the best choice?

Partly duplicate of this question

like image 790
Drakosha Avatar asked May 19 '09 05:05

Drakosha


2 Answers

IMHO the closest to come to a power outrage is to run the application in a VM and to power of the VM without shutting down. In all other cases where the OS is still running when the application terminates the OS will do some cleanup that would not occur in a real power outage.

like image 107
lothar Avatar answered Nov 06 '22 18:11

lothar


At the application level, the most violent you can get is _exit(). Division by zero, segfaults, etc are all signals, which can be trapped - if untrapped, they're basically the same as _exit(), but may leave a coredump depending on the signal.

If you truly want a hard shutdown, the best bet is to cut power in the most violent way possible. Invoking /sbin/poweroff -fn is about as close as you can get, although it may do some cleanup at the hardware level on its way out.

If you really want to stress things, though, your best bet is to really, truly cut the power - install some sort of software controlled relay on the power cord, and have the software cut that. The uncontrolled loss of power will turn up all sorts of weird stuff. For example, data on disk can be corrupted due to RAM losing power before the DMA controller or hard disk. This is not something you can test by anything other than actually cutting power, in your production hardware configuration, over multiple trials.

like image 28
bdonlan Avatar answered Nov 06 '22 18:11

bdonlan