LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How to overcome segmentation fault error? (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-overcome-segmentation-fault-error-4175697845/)

irajjs 07-17-2021 12:15 AM

How to overcome segmentation fault error?
 
Hi
Tens of my own created programs are aborted by kernel due to segmentation fault error
I have searched but I have not found any acceptable solution!
There are some suggestions about using gdb but I know that it will not solve the problem
I have created my own debugger program but that also gets the segmentation fault error and stopped!
I tried using insmode and modeprobe commands but they do not work too!
Shall I create my own kernel?
Or is there a way to control the current kernel and overcome this segfault error?
Thank you in advance for any answer

berndbausch 07-17-2021 01:19 AM

Quote:

Originally Posted by irajjs (Post 6267174)
There are some suggestions about using gdb but I know that it will not solve the problem

Why?

Quote:

I tried using insmode and modeprobe commands but they do not work too!
They insert kernel modules and are unlikely to have anything to do with your programs. How do they fail?
Quote:

Shall I create my own kernel?
Or is there a way to control the current kernel and overcome this segfault error?
Segmentation faults come from programming errors, or from binaries that are incompatible with libraries or your kernel. The first step is finding out which code line provokes the error. This can be done post-mortem with a core file and a debugger like gdb. You can also try a development environment like Eclipse.

syg00 07-17-2021 03:44 AM

Quote:

Originally Posted by irajjs (Post 6267174)
Tens of my own created programs are aborted by kernel due to segmentation fault error
I have searched but I have not found any acceptable solution!

Learn to code clean code - the kernel is not the problem, you are.
Quote:

There are some suggestions about using gdb but I know that it will not solve the problem
I have created my own debugger program but that also gets the segmentation fault error and stopped!
Yet more evidence that you don't understand the problem. If you are actually writing kernel modules (scary thought) then yes you might need to recompile the kernel with appropriate config options; debug_info and kgdb at a minimum. Lots of legwork ahead I reckon.

hazel 07-17-2021 04:40 AM

99% of segmentation faults are caused by the programmer doing something silly with a pointer. Start by finding out exactly where the program crashes. If you can use gdb for that, so much the better. I could never get my head around that (too old, I reckon) so I would insert little messages and move them forward step by step through the program until the message failed to print before the crash. Then I knew where the crash was occurring. Messages to indicate the entry into and exit from functions are useful too. And in some cases, printing out the actual value of a pointer can help. I once had a program that crashed because a supposedly incrementing pointer wasn't incrementing.

sundialsvcs 07-17-2021 11:30 AM

Invariably, segmentation-faults are caused by one of two things:
  • The pointer value was never initialized. (For instance, you used malloc() to allocate the storage, instead of calloc() which sets the entire block to zero.)
  • When you discarded a block of memory referred-to by a pointer, you did not immediately set the pointer value to zero (NULL, nullptr).
  • You did not test whether a pointer's value was NULL before using it.

A whole lot of this is unfortunately self-discpline, although object-oriented languages like C++ do make things considerably easier to keep track of.

In any case – "it's not the kernel's fault."

irajjs 07-17-2021 01:41 PM

My answer
 
First:
Here I want to say thank you to the 3 high rank LQ members who have answered my post
May be I am the problem! And maybe I have done some silly things!
But currently I have created more than 600 programs and many of them do not work because of segfault
I know that my programs are not compatible with libraries and or kernel! But my understanding is that Linux is a free software and so it must be changeable so I do not care about compatibility!

Commands like insmde or modprobe failed because of this or something like that error:
Module not supported

As I searched segfault happens when a program trys to access parts of memory which is not allowed!
I want my own programs to access all parts of OS if needed! This is how I intended them to work! So considering some terminal outputs like:
Permission denied
Or
Segmentation fault
Or
S_create ... Aborted etc
I think the kernel is involved because the only program which can stand/stop root seems to be kernel
Anyhow I want my own programs to be the leader in OS and not an slave
I am trying to change the system as I like and I think that I have the right to do so because of as I said OS is a free software
So if possible help me to overcome kernel/system
Thank you

berndbausch 07-17-2021 02:10 PM

You seem to confuse "free software" with "error-free software", and "the right to change the kernel" with "guarantee that whatever I do, my programs will run".

Free software or not, if your programs are not compatible, they don't run. Use the tips you received.

irajjs 07-18-2021 12:37 AM

Illogical errors
 
Quote:

Originally Posted by berndbausch (Post 6267298)
You seem to confuse "free software" with "error-free software", and "the right to change the kernel" with "guarantee that whatever I do, my programs will run".

Free software or not, if your programs are not compatible, they don't run.

Actually I have disabled most useless , illogical errors
The code causing error is like this:
If something then stop working/die/print-something ...etc
So if you change the code the behaviour will change
I am using c++ and g++ compiler
During last 10 years I have reinstalled OS several times in cases I have succeeded and sometimes I was confronted with the emergency state!
I even had disabled entering emergency state by changing the related code
This time the system seems to become stronger! And I am tired of reinstalling the OS! Because every time I have to start from beginning and change a lot of settings!
Now my commands do not work as I expect
For example I coded as this:
If segfault then ignore/continue/do-not-abort ...etc
This is why I asked for help
With or without help I will try to succeed and go ahead but I am not sure about the result! You know I am 71 years old now .. who knows about the future!
Thank you for your attention but I can not return!

hazel 07-18-2021 05:26 AM

Quote:

Originally Posted by irajjs (Post 6267289)
I know that my programs are not compatible with libraries and or kernel! But my understanding is that Linux is a free software and so it must be changeable so I do not care about compatibility!

That's a crazy notion. If different bits of software are to work together, of course they have to be compatible.
Quote:

As I searched segfault happens when a program trys to access parts of memory which is not allowed!
I want my own programs to access all parts of OS if needed! This is how I intended them to work!
Segmentation faults occur because one process has tried to access memory which belongs to another process or to the kernel. This normally happens because a pointer acquires a silly value due to programming errors. If you want your programs to misbehave, why complain when they get their knuckles rapped for misbehaving?
Quote:

I think the kernel is involved because the only program which can stand/stop root seems to be kernel
That at least is correct. It is the kernel that polices the processes and crashes any process which is interfering with another process's memory. Would you rather have the whole system crashing and giving you a blue screen of death, as happens with Windows?
Quote:

Anyhow I want my own programs to be the leader in OS and not an slave
I am trying to change the system as I like and I think that I have the right to do so because of as I said OS is a free software.
In other words, you want your programs to behave like psychopaths and you want the kernel to let them do it! Oh boy!!:tisk:

igadoter 07-18-2021 05:57 AM

I don't know why we discuss this at all. As well OP may try to walk upside-down. And complain that it doesn't work.

sundialsvcs 07-18-2021 09:04 AM

Yep. "It must be somebody else's fault." Maybe you can pay a lawyer to sue Linus Torvalds, since it's his kernel – maybe it's his fault. Or, the guy who comes twice a week to empty your waste bin – maybe it's his fault!

Or maybe you could sue the segment – obviously, it must be its fault: the computer just said so!

hazel 07-18-2021 09:41 AM

istr reading somewhere that in early UNIX systems, segment violations were not policed effectively and systems often crashed because some badly-written program had overwritten a piece of the kernel. One of the superior things about Linux is the way the kernel polices the processes so that the system almost never crashes. Now this OP wants to return to the dark ages!

irajjs 07-18-2021 09:51 AM

Not on my side!
 
I am not complaining about kernel behaviour! I want to make/force kernel to do what I want to be done! Because I am trying to develop all software in my computer even the current kernel!
One of my programs is named as:
LAUHL which is an abreviation for:
Learn And Use Human Languages

I want to automatically upgrade software in my computer
After that my intention is to share my knowledge with everyone
But kernel/system do not or can not understand that , so they work as they are designed to work and any upgrade is designed to be done by parental site!
Why?!
Finally there would be no harm if my programs can access the memory related to other segments because generally my programs are designed to automatically upgrade computer
Other software can not understand this and resist! My own made programs have always been restricted! They do not or can not remember their own work! In spite of my save/remember commands!
My help request was because I assumed you are on my side! Are you?!

hazel 07-18-2021 11:25 AM

Quote:

Originally Posted by irajjs (Post 6267492)
But kernel/system... work as they are designed to work

That's not a bug, it's a feature :smirk:

zeebra 07-21-2021 12:28 PM

Perhaps a better place for this thread would be here:
https://www.linuxquestions.org/questions/programming-9/


All times are GMT -5. The time now is 09:35 PM.