I'm working on a simple game console for raspberry pi, and I want to handle some common errors like segmentation fault, arithmetic exception and input/output error (since there maybe some guys using horrible SD cards).

when handler program detect the return code of my game, just show the corresponding error message on monitor.

I can easily test my handler by accessing null pointer or doing division by zero to trigger segmentation fault and arithmetic exception. But how to write a test program to trigger input/output error?

  • You seem to be confusing apples and pumpkins.  Segmentation fault and arithmetic exception are signals that, by default, cause the process to terminate in a characteristic way.  Input/output errors are just result codes that a program can ignore, or can handle in any way.  For example, cat file1 file2 and grep pattern file1 file2 issue an error message if file1 does not exist, but they go on to process file2.  (They ultimately exit with error status codes.)  Bash doesn’t care if ~/.bashrc doesn’t exist.  … (Cont’d) – G-Man Apr 12 at 17:09
  • (Cont’d) …  There’s no way for a parent process to know that a child process has encountered an I/O error (except by tracing it).  The best you can do is check the exit status when it terminates, and different programs use different exit codes to mean different things.  If I’m misunderstanding what you’re asking for, please edit your question to make it clearer and more complete. – G-Man Apr 12 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.