Difference between a bus error and a segmentation fault? Can it happen that a program gives a seg fault and stops for the first time and for the second time it may give a bu
This would be a dup of What is a bus error?, if it weren't for the
Can it happen that a program gives a seg fault and stops for the first time and for the second time it may give a bus error and exit ?
part of the question. You should be able to answer this for yourself with the information found here.
Insanity: doing the same thing over and over again and expecting different results.
-- Albert Einstein
Of course, taking the question literally...
#include
#include
#include
#include
int main() {
srand(time(NULL));
if (rand() % 2)
kill(getpid(), SIGBUS);
else
kill(getpid(), SIGSEGV);
return 0;
}
Tada, a program that can exit with a segmentation fault on one run and exit with a bus error on another run.