ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
There are code tags that can be used in post which will make it s/possible/easier/ to read your code.
Use stderr and write frequent output statements to isolate where the program segfaults. Remove all parts not related to the segfault and you will either be able to find your problem or have something you can post that someone can help with.
Segfaults indicate you are either using an uninitialized pointer or writing to memory that isn't reserved for your programs use.
Rather use gdb which will stop at the exact point in the program where the segfault occurs.
Well, yes, or for that matter run valgrind and likely find the problem itself. There's a number of approaches that are going to have an improved chance of success over posting a long, unformatted chunk of code.
in "c " right ? not c++ or c#
what standard of c is it ?
c11 or an older version c99 ?
what compiler are you using ?
How are you building this unknown program ?
-- the full build line if it is a simple program (EXAMPLE: gcc Program.c -o Program -lm )
What dose this "program" do "
Are there libraries that it NEEDS that you did NOT tell gcc to use ( -lm ??? ) ?
please POST the code -- and use code tags please
-- using the PHP tags to show the std code tags
PHP Code:
[code] the code line1 line2 line3 and so on [/code]
There's a variety of things you can do. If you set ulimit -c to be unlimited in your command prompt from where you run your program, it should generate a core file. Further, when you compile, presuming you're using gcc, then use the -ggdb argument to generate GDB debugging symbols and information. You can then use GDB to analyze a core file, see the backtrace, and then determine what went wrong. Or as also suggested, run from within GDB, let it break, and analyze what happened by looking at the stack and backtrace. If things get completely screwed up and you can't see what happened. Output some debug to determine how far you have gotten in your program, single step through it in the debugger, and so forth. You may want to post your code as well, but before doing so, you should try to zero in on what parts of it work and what doesn't. For instance if it's a very lengthy piece of code and it does a lot of operations before having the segmentation fault, then it will be inefficient to have people view a lot of code, they either may not or they may focus on code style or things which might be warnings versus find the location where the actual fault is.
So what is the problem ?
Im not able to figure out the reason for segmentation fault!!
Thanks very much for every help
Quote:
Originally Posted by NevemTeve
Well, you've deleted the code, but should you post it again, use [code] and [/code] tags.
If you found your solution. Please do not delete the code from your original post and instead post and update to indicate what the problem was and how you fixed it. It appears you originally posted code, but deleted it. A better thing would be edit that original to post within code tags correctly. And then post an update, mark the solution as solved. This way someone else can benefit by your problem and solution. Otherwise this becomes a wasted thread which will garner some attention, but end up helping no one. In fact future searches for it will find it if someone is searching for segmentation faults, and then they'll be frustrated in not seeing any example of the solution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.