In fedora machine, I am handling segv signal, doing some cleanup and then generating core file using

SignalHandler(){
// Do Cleanup
// For generation of core file
    signal(a, SIG_DFL); 
    kill(getpid(), a);
    }

But When I run a multi threaded program, the core file seems to point to a place completely unrelated to where the seg fault has occurred. Is there any work around for this??

Say there are 3 thread m (main), t1, t2
if segv happened in t2, I am seeing the core file to point to some unrelated code in m. I think by the time I catch the signal and do cleanup and generate the core file, the backtrace stack is getting changed..

Also m is running a tcp server, waiting for connections from client. So mostly I am finding the core to point at this point: in accept call of tcp.

Any way in which I can make the core to point at the correct place?? Since it is necessary for me to handle segv and do some cleanup.

Have you tried pthread_kill (pthread_self (), sig) ?

Since I am handling segv generated by thread t1 in thread m, does pthread_self() point to thread m; is there a way I can kill the target thread, t1 in this case.

Anyways, will try that..tq.

You can call pthread_kill on any valid thread identifier. The trick is getting a handle to that thread. If you've already got a handle to the thread in question they you can provide that. pthread_self on the other hand, returns the identifier of the currently active thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.