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.
I am trying to write a peer to peer application in C++ using pthreads library. There are few types of nodes that run in the program. The 'beacon' nodes form the core of the network. The ordinary nodes 'join' the network by sending join requests to the beacon node.
So, my program runs till the join requests and responses are received. When I try to 'connect' using connect function from the socket library, I get a segfault. I am not sure if the segfault occurs for the connect function, because sometimes the program just runs to completion. It could be an issue related to threads or memory allocation.
When I run gdb, it shows me the following:
Code:
(gdb) run b2-n00.ini
Starting program: sv_node b2-n00.ini
servant:12600> [New LWP 1]
[New LWP 2]
[New LWP 3]
[New LWP 4]
[New LWP 5]
[New LWP 6]
Before Exiting[LWP 1 exited]
procfs: fetch_registers, get_gregs line 3768, /proc/23952/lwp/1: No such file or directory.
I am really not sure what's happening. Any pointers on what's going on?
that doesn't look like a typical segmentation fault (SIGSEGV, signal 11) reported by GDB ;-). I made a quick google search and found that the listed functions belong to the GDB code, so I would for now assume that this is a bug in some old GDB. Which version of GDB are you running (gdb --version). The newest version is 7.0.1. I think that - after upgrading to a newer version - you should then be able to see where the segmentation fault really happens and which parameter of connect(2) causes the crash.
For a short-term satisfaction you could also attach your source code (please DON'T post) and I'll try on my system ...
- Andi -
Last edited by ForzaItalia2006; 03-17-2010 at 02:34 PM.
ouch, that doesn't look good :-) From past experiences, a segmentation fault in one of the malloc/free functions really often indicates heap corruption, meaning that you possibly double free(3)ed a pointer or wrote past the allocated memory area and overwrote some malloc-specific meta-data.
The easiest way to figure out which part of your app causes the heap corruption, I would recommend using the 'valgrind' utility, especialy the memcheck tool of 'valgrind' should do it right.
Well, I tried to install the valgrind utility on the server that I am working on(My code is supposed to run on a particular server machine, so I am working on it directly, rather than on a local machine), but that machine did not let me do so.
So, I am still using gdb .. And I am still getting the segfault when I try to push a struct on the queue.
I am using STL queues, and I have an array of queues. I wonder if STL takes care of memory allocation by it's own.
I tried putting the struct in different queues(from the array of queues), but all of them return a segfault which makes me believe it is something relating to memory allocation/corruption.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.