Linux ошибка сегментирования сделан дамп памяти

How to resolve «Segmentation fault (core dumped)»

I am using Ubuntu 14.04. After installing some applications I faced a segmentation fault (core dumped) error. What does it mean ? How can I resolve this issue ? For example: After installing chrome-stable, when I launch it from terminal I experience this error.

Some binary program crashed, but this is very specific to the program that crashed, so you may need to tell us which program produced this, also you could try to update it.

Try remove it’s preferences & cache, sudo rm -rf ~/.config/google-chrome ~/.cache/google-chrome . Then run it is incognito mode google-chrome —incognito

1 Answer 1

What does it mean?

See AU: What is a segmentation fault? post and also this post which have some examples how reproduce it, SO: What is segmentation fault?.

The simplest description I can come with (may be not the perfect):

The program tried to access a memory area out side its own section. Operating system blocks it.

Some cases: Reading value with uninitialized pointer, Going out of range in an array, Function call (when backward compatibility not maintained), .

However, it is not always easy find the cause with large programs or those which relay on other project lib’s. And most of the cases end up with a bug report, either for target program or one of its dependencies (either upstream project or downstream distribution package).

How can I resolve this issue?

Fire a bug report

Take initiative to debug

Some Useful Tools for Debugging

Some . I mean there are many other useful tools out there that you gonna find when you dig in more.

apport-bug logs / core dump / backtrace

If you don’t have an error message before segmentation fault. Run it with —save option and look for back-trace log:

apport-bug program-cmd --save bug-report_output.txt 

gdb backtrace / debuging source code

$ gdb program-cmd (gdb) run (gdb) backtrace 

If you get any error message, check the web, launchpad and in upstream project bug tracker if there any similar cases. For some advanced users or who are following a c/c++ learning path, they could download the corresponding -dbg symbols packages. Then you can use gdb to trace program flow through the source and get the exact function/instruction that raise the runtime error. For Ubuntu(Debian) based distributions, source code of a package can be downloaded using:

Читайте также:  Can you install linux on android phone

strace system call tracing

In the simplest case strace runs the specified command until it exits. It intercepts and records the system calls which are called by a process and the signals which are received by a process. The name of each system call, its arguments and its return value are printed on standard error or to the file specified with the -o option. strace is a useful diagnostic, instructional, and debugging tool. System administrators, diagnosticians and trouble-shooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them. Students, hackers and the overly-curious will find that a great deal can be learned about a system and its system calls by tracing even ordinary programs. And programmers will find that since system calls and signals are events that happen at the user/kernel interface, a close examination of this boundary is very useful for bug isolation, sanity checking and attempting to capture race conditions.

ltrace dynamic library call tracing

ltrace is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls exe‐ cuted by the program. Its use is very similar to strace (1).

Источник

Ошибка сегментирования (сделан дамп памяти)

Всем доброго времени суток, уважаемые гуру. Ребят, подскажите пожалуйста, кто в теме. Написал обычную программу на языке с++. Компилирую командой «g++ main.cpp -fopenmp», и компилируется без ошибок. А когда запускаю её на выполнение командой «./a.out «, в терминале пишет: Ошибка сегментирования (сделан дамп памяти)
Подскажите в чём может быть проблема? Причём всё работает, при изменении параметра n

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include #include #include #include #include #include using namespace std; int main(int argc, char *argv[]){ int N = 1; int n = 100; //typedef complex complexd; complexdouble> a[int (pow(2,n))]; for (int i=0; ipow(2,n);i++){ a[i] = complexdouble>(rand() % 9 + 1 , rand() % 9 + 1); //cout } complexdouble> b[int (pow(2,n))]; complexdouble> U[2][2]; U[0][0] = complexdouble> (0); U[0][1] = complexdouble> (1); U[1][0] = complexdouble> (1); U[1][1] = complexdouble> (0); omp_set_dynamic(0); // запретить библиотеке openmp менять число потоков во время исполнения omp_set_num_threads(N); // установить число потоков в 10 int power = pow(2,n); #pragma omp parallel for shared(a, b, U) private(i) for (int i = 0; i  power; i++){ //cout switch ((i+1)%4) { case 1: b[i] = U[0][0]*a[i]+U[0][1]*a[i+2]; break; case 2: b[i] = U[0][0]*a[i]+U[0][1]*a[i+2]; break; case 3: b[i] = U[1][0]*a[i-2]+U[1][1]*a[i]; break; case 0: b[i] = U[1][0]*a[i-2]+U[1][1]*a[i]; break; default: break; } } cout<("\n"); // for (int i=0; i // cout // > int t = clock(); cout ; cout<((float)t) / CLOCKS_PER_SEC<"\n"; return 0; }

Ошибка сегментирования (сделан дамп памяти)
в обще пишу игрушку с помощью sfml библиотек такая пробема на одном из этапов написания после.

Ошибка сегментирования (сделан дамп памяти)
Доброго времени суток. На текущий момент имеется программа, позволяющая выводить различные вариации.

Ошибка сегментирования (сделан дамп памяти)
В универе задали задание "Реализовать программу определения полного имени файла(подъем по дереву.

Ошибка сегментирования (сделан дамп памяти)
Доброй ночи Подскажите как при программировании на C++ под LINUX (UBUNTU) избавиться от ошибки.

Эксперт .NET

Лучший ответ

Сообщение было отмечено Bacek_Tm как решение

Решение

Падает со stack overflow еще до вызова функции main, скорее всего из-за выделения слишком большого массива (a и b). Выделите его динамически через new.

complexdouble> *a = new complexdouble>[power]; complexdouble> *b = new complexdouble>[power]; . delete[] a; delete[] b;

Someone007, спасибо. это действительно помогло. Но теперь уже при n = 26+ выпадает другая ошибка также при выполнении программы. Я полагаю это от того, что слишком большие значения для компьютера. Всё же как никак показательная степень используется. Выпадает ошибка:

vasiliy@vasiliy-HP-ProBook-4530s:~/QT projects/Qubit$ g++ main.cpp -fopenmp vasiliy@vasiliy-HP-ProBook-4530s:~/QT projects/Qubit$ ./a.out terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Аварийный останов (сделан дамп памяти) vasiliy@vasiliy-HP-ProBook-4530s:~/QT projects/Qubit$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include #include #include #include #include #include using namespace std; int main(int argc, char *argv[]){ int N = 1; int n = 27; //typedef complex complexd; int power = int (pow(2,n)); complex double> *a = new complex double>[power]; complex double> *b = new complex double>[power]; for (int i=0; ipower;i++){ a[i] = complexdouble>(rand() % 9 + 1 , rand() % 9 + 1); //cout } complexdouble> U[2][2]; U[0][0] = complexdouble> (0); U[0][1] = complexdouble> (1); U[1][0] = complexdouble> (1); U[1][1] = complexdouble> (0); omp_set_dynamic(0); // запретить библиотеке openmp менять число потоков во время исполнения omp_set_num_threads(N); // установить число потоков в 10 #pragma omp parallel for shared(a, b, U) private(i) for (int i = 0; i  power; i++){ //cout switch ((i+1)%4) { case 1: b[i] = U[0][0]*a[i]+U[0][1]*a[i+2]; break; case 2: b[i] = U[0][0]*a[i]+U[0][1]*a[i+2]; break; case 3: b[i] = U[1][0]*a[i-2]+U[1][1]*a[i]; break; case 0: b[i] = U[1][0]*a[i-2]+U[1][1]*a[i]; break; default: break; } } cout<("\n"); // for (int i=0; i // cout // > delete[] a; delete[] b; int t = clock(); cout ; cout<((float)t) / CLOCKS_PER_SEC<"\n"; return 0; }

Добавлено через 3 минуты
Someone007, а подскажите ещё пожалуйста про функцию clock(), я хочу замерить время работы программы. А эта функция выдаёт не соответствующее время работы самой программы. Т.е. пишет, что проработала 18.5629 секунд, а на самом деле секунд 5.

Эксперт .NET

2^27=0x08000000, 0x08000000*8*2=0x80000000 байт = минимум 2 ГБ памяти (а скорее всего даже больше, зависит от внутреннего устройства std::complex, у меня выделилось 4 ГБ при 27 степени на 64 битной винде и не упало). Это значение в int не укладывается, но падает скорее всего из-за нехватки памяти.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include #include #include #include #include #include using namespace std; int main(int argc, char *argv[]){ clock_t t = clock(); int N = 1; int n = 27; //typedef complex complexd; int power = int(pow(2, n)); complex double> *a = new complex double>[power]; complex double> *b = new complex double>[power]; for (int i = 0; i  power; i++){ a[i] = complexdouble>(rand() % 9 + 1, rand() % 9 + 1); //cout } complexdouble> U[2][2]; U[0][0] = complexdouble>(0); U[0][1] = complexdouble>(1); U[1][0] = complexdouble>(1); U[1][1] = complexdouble>(0); omp_set_dynamic(0); // запретить библиотеке openmp менять число потоков во время исполнения omp_set_num_threads(N); // установить число потоков в 10 #pragma omp parallel for shared(a, b, U) private(i) for (int i = 0; i  power; i++){ //cout switch ((i + 1) % 4) { case 1: b[i] = U[0][0] * a[i] + U[0][1] * a[i + 2]; break; case 2: b[i] = U[0][0] * a[i] + U[0][1] * a[i + 2]; break; case 3: b[i] = U[1][0] * a[i - 2] + U[1][1] * a[i]; break; case 0: b[i] = U[1][0] * a[i - 2] + U[1][1] * a[i]; break; default: break; } } cout  <("\n"); // for (int i=0; i // cout // > delete[] a; delete[] b; t = clock() - t; cout   ; cout  <((float)t) / CLOCKS_PER_SEC  <"\n"; return 0; }

Источник

Оцените статью
Adblock
detector