Alex Rivera | Logout

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

Asked 2009-05-19T05:10:29.800
15

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?

It is partly a duplicate of this question.

Edit
Report

1 Answer

15

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.

answered 2009-05-19T05:57:53.340

Your Answer