In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you what the simple problems of Segmentation fault are. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something through the detailed introduction of this article.
Some programs compile, but Segment faults occur at runtime. This is usually caused by a pointer error. But instead of prompting a file line like a compilation error, there is no information. One way is to use the step of gdb to find it step by step. But it's hard to imagine stepping into tens of thousands of lines of code. We have a better way, this is the core file.
If you want the system to generate core files when an error is caused by a signal interrupt, you need to set the following in the shell:
#Set core size to unlimited ulimit -c unlimited
#Set file size to unlimited ulimit unlimited
After the core dump occurs, use gdb to view the contents of the core file to locate the line in the file that caused the core dump:
gdb [exec file] [core file]
For example: gdb ./ test test. coreAfter entering gdb, check the backtrace with bt to see where the generator runs to locate the file-> line of the core dump.
Another thing to note is that if you have a lot of applications running on your machine and you don't know which application generated the core, you can view it with the following command: file core
A few questions:
1. What is Core:
Before using semiconductors as memory materials, humans used coils as memory materials (invented by Wang An), coils were called core, and memories made of coils were called core memory. Today, the semiconductor industry is booming, and no one uses core memory anymore, but in many cases, people still call memory core.
2. What is Core Dump:
When we develop (or use) a program, our greatest fear is that the program will fail somehow. Although the system is fine, we may still encounter the same problem next time. Then the operating system dumps the memory contents of the program when it is dropped (now usually written in a file called core) for us or debugger to refer to. This is called a core dump.
3. What files are generated when Core Dump:
When Core Dump, a file such as core. process number is generated.
4. Why is it that sometimes the program is Down, but it doesn't generate a Core file?
Resources available to the shell and to processes. may be used
#ulimit -a Look at these settings. (ulimit is bash built-in Command)
From here it can be seen that if-c is displayed: core file size. If this value is 0, the core file cannot be generated. So you can use: #ulimit -c 1024 or #ulimit -c unlimited to enable core files. If a Core file is generated when the program makes an error, Segmentation fault (core dumped) is displayed.
5. Core Dump's core dump file directory and naming convention:
/proc/sys/kernel /core_uses_pid can control whether pid is added to the file name of the generated core file as an extension. If so, the file content is 1, otherwise it is 0.
This file can be modified by the following command:
echo "1" > /proc/sys/kernel/core_uses_pid
6. How to use Core files:
Under Linux, use:
#gdb -c core.pid program_name
You can enter GDB mode.
Enter where, you can indicate which line is dropped, which function, who calls it, and so on.
(gdb) where
Or enter bt.
(gdb) bt
7. How to get a normal program down:
#kill -s SIGSEGV pid
8. See where the Core file output is:
The directory where the Coredump is stored is the current directory of the process, typically the directory where the command to start the process was issued. But if it is started by a script, the script may modify the current directory, and the process's true current directory will be different from the directory where the script was executed. At this point, you can look at the target of the "/proc//cwd" symbolic link to determine the true current directory address of the process. Processes started through system services can also be viewed in this way.
proc/sys/kernel /core_pattern controls where core files are saved and file name format.
This file can be modified by the following command:
echo "/corefile/core-%e-%p-%t" >core_pattern
The core file can be uniformly generated under the/corefile directory, and the resulting file name is core-command name-pid-timestamp.
The following is a list of parameters:
%p - insert pid into filename add pid
%u - insert current uid into filename Add current uid
%g - insert current gid into filename
%s - insert signal that caused the coredump into the filename
%t - insert UNIX time that the coredump occurred into filename
%h - insert hostname where the coredump happened into filename Add hostname
%e - insert coredumping executable name into filename
In Linux, to ensure that the program crashes when generating Coredump to pay attention to these issues:
Make sure that the directory where Coredump is stored exists and that the process has write permissions to that directory. The directory where the Coredump is stored is the current directory of the process, typically the directory where the command to start the process was issued. But if it is started by a script, the script may modify the current directory, and the process's true current directory will be different from the directory where the script was executed. At this point you can look at the target of the "/proc/process pid>/cwd" symbolic link to determine the true current directory address of the process. Processes started through system services can also be viewed in this way.
If the program calls seteuid()/setegid() to change the valid users or groups of a process, then by default the system does not generate Coredump for these processes. Many services call seteuid(), such as MySQL, and no matter what user you run mysqld_safe with to start mysql, the valid user for mysqld is always the mysql user. If you run a program as user A, but see it in ps as user B, then those processes are calling seteuid. In order for these processes to generate core dumps,/proc/sys/fs needs to be
The contents of the/suid_dumpable file are changed to 1 (usually 0 by default).
Third, this is generally known, that is, to set a large enough Core file size limit. The size of the Core file generated when the program crashes is the size of the memory occupied by the program while it is running. However, the behavior of the program crash cannot be estimated according to the usual behavior, such as buffer overflow errors may cause the stack to be destroyed, so it often occurs that the value of a variable is modified to a mess, and then the program uses this size to request memory. So no matter how little memory your program uses to run properly, it's better to make sure you generate Core files or set the size limit to unlimited.
4. Will an abnormal exit generate a core? Isn't there an exception exit that doesn't generate core?
If it is not a normal exit, it is a signal that causes the program to exit. Some signals can indeed cause the program to exit without generating core.
SIGHUP Terminates Process Terminal Line Hang-Up
SIGINT Terminates Process Interrupts Process
SIGQUIT Create CORE file Terminates process and generates core file
SIGILL Create CORE file illegal instruction
SIGTRAP Create CORE File Tracking Trap
SIGBUS Error creating CORE file bus
SIGSEGV illegal error creating CORE file segment
SIGFPE Create CORE File Floating Exception
SIGIOT Create CORE File Perform I/O Trap
SIGKILL Terminates Process Kills Process
SIGPIPE terminates the process by writing data to a pipe that has no read process
SIGALARM Terminate Process Timer expires
SIGTERM terminate process software terminate signal
SIGSTOP stop process non-terminal stop signal
SIGTSTP Stop Process Stop Signal from Terminal
SIGCONT ignores the signal to continue executing a stopped process
SIGURG Ignore Signal I/O Emergency Signal
SIGIO Ignore I/O is possible on signal descriptors
SIGCHLD ignore signal notifies parent process when child process stops or exits
SIGTTOU Stop process daemon write terminal
SIGTTIN Stop Process Daemon Read Terminal
SIGXGPU Terminate Process CPU timeout
SIGXFSZ Terminate process file length is too long
SIGWINCH ignore signal window size changes
SIGPROF Terminate Process Statistical Distribution Plot with Timer Expiration
SIGUSR1 Terminate Process User Defined Signal 1
SIGUSR2 Terminate Process User Defined Signal 2
SIGVTALRM Terminates Process Virtual Timer to
Set the possible signals on the handle, see what kind of situation.
A segmentation fault is caused by an exception in the virtual memory management unit, which is usually caused by dereferencing a pointer with an uninitialized or illegal value.
Linux provides core dump functionality to make debugging for this type of error easier.
In general, Linux systems are not allowed to generate core files, so first remove this restriction:
ulimit -c unlimited
Next, run segment programs with segmentation faults, such as:
./ test
At this point, the segmentation fault error message will be displayed as:
Segmentation fault (core dumped)
A file named core will appear under this folder
Debugging using the generated core file
gdb test core
(gdb) bt
#0 0x00a5c920 in ?? () from /lib/i386-linux-gnu/libc.so.6
#1 0x00a5ca0d in exit () from /lib/i386-linux-gnu/libc.so.6
#2 0x00a4311b in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
#3 0x080483d1 in _start ()
The above is the simple question of Segmentation fault. What are you learning? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.