Linux 上的分段错误是什么? [英] What is a segmentation fault on Linux?

查看:21
本文介绍了Linux 上的分段错误是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux 中:

什么是分段错误?我知道它会使程序崩溃,但这是某种内存泄漏问题,还是完全不相关的问题?还有,你是怎么处理这些的?这通常是计算机设置的问题,还是应用程序本身的问题?

What is a segmentation fault? I know it crashes programs, but is that some sort of memory leak problem, or something completely unrelated? Also, how do you deal with these? Is this typically a problem with the computer set-up, or within the application itself?

另外,其他操作系统也会出现这种情况吗?

Also, does this happen in other OS's as well?

推荐答案

当您的程序尝试访问未被操作系统分配或不允许访问的内存时,就会出现分段错误.

A segmentation fault is when your program attempts to access memory it has either not been assigned by the operating system, or is otherwise not allowed to access.

分段"是指计算机上的每个进程都有自己独特的虚拟地址空间.因此,当进程 A 读取内存位置 0x877 时,与进程 B 读取自己的 0x877 时相比,它读取驻留在 RAM 中不同物理位置的信息.

"segmentation" is the concept of each process on your computer having its own distinct virtual address space. Thus, when Process A reads memory location 0x877, it reads information residing at a different physical location in RAM than when Process B reads its own 0x877.

所有现代操作系统都支持和使用分段,因此都可能产生分段错误.

All modern operating systems support and use segmentation, and so all can produce a segmentation fault.

要处理分段错误,请修复导致它的代码.它通常表示编程不佳,尤其是边界条件错误、不正确的指针操作或对共享库的无效假设.有时段错误和任何问题一样,可能是由硬件故障引起的,但通常情况并非如此.

To deal with a segmentation fault, fix the code causing it. It is generally indicative of poor programming, especially boundary-condition errors, incorrect pointer manipulation, or invalid assumptions about shared libraries. Sometimes segfaults, like any problem, may be caused by faulty hardware, but this is usually not the case.

这篇关于Linux 上的分段错误是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆