What is wrong with pthread_kill on Redhat Linux ???
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > What is wrong with pthread_kill on Redhat Linux ???




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    What is wrong with pthread_kill on Redhat Linux ???  
Anoop Kumar


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:36 PM

Hi,
I have redhat 9.0 Linux installed on my system with gcc 3.2.3.
This is the program i used, i compiled it with -lpthread option.

Here i am starting 3 threads and then i am calling pthread_kill on a
thread which is non-existent , the signal being passed is '0'.
According to the POSIX standard if the thread doesn't exist it should
set errno to ESRCH. But instead it causes a segmentation fault.
Why is that ???
Is there any work around to this problem ???
Is this a linux problem or just Redhat 9.0 problem???

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include<signal.h>
#include <errno.h>

void* do_loop(void* data)
{
long int i;
int j;
int me = *((int*)data);

while (1) // infinite loop
{
i++;
if( i%1000000== 0)
printf("thread %d - i val %d\n", me, i);
if(i==225000000)
pthread_exit(NULL);
}
pthread_exit(NULL); // There is no point of this actually
}

int main()
{
int        thr_id;
pthread_t  id;
int        a = 1;
int        b = 2;
int        c = 3;
int        d = 4;

if(pthread_create(&id, NULL, do_loop, (void*)&a) != 0)
printf(" Thread creation Failure \n");

if(pthread_create(&id, NULL, do_loop, (void*)&c) != 0)
printf(" Thread creation Failure \n");

if(pthread_create(&id, NULL, do_loop, (void*)&d) != 0)
printf(" Thread creation Failure \n");

if(pthread_kill((pthread_t)19820, 0) == ESRCH)
{
printf("Main Thread:  Thread not found \n");
}

else
{
printf(" Thread Found !!!.... Killing\n");
sleep(10);
pthread_kill(id,SIGKILL);
}
return 0;
}


//P.S : This very same program works on Solaris!!!





[ Post a follow-up to this message ]



    Re: What is wrong with pthread_kill on Redhat Linux ???  
examnotes


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:36 PM

anoop_kn@yahoo.com (Anoop Kumar) writes:
quote:
> Hi, > I have redhat 9.0 Linux installed on my system with gcc 3.2.3. > This is the program i used, i compiled it with -lpthread option. > > Here i am starting 3 threads and then i am calling pthread_kill on a > thread which is non-existent , the signal being passed is '0'. > According to the POSIX standard if the thread doesn't exist it should > set errno to ESRCH. But instead it causes a segmentation fault. > Why is that ??? > Is there any work around to this problem ??? > Is this a linux problem or just Redhat 9.0 problem???
It's a weakness in the new NPTL thread library used by redhat 9. pthread_kill and a few other functions cast the pthread_t to a pointer and attempt to dereference it. Obviously, this will cause a segmentation fault. The only workaround I can think of is not to pass invalid thread IDs to these functions. -- Måns Rullgård mru@kth.se




[ Post a follow-up to this message ]



    Re: What is wrong with pthread_kill on Redhat Linux ???  
Artie Gold


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:36 PM

Måns Rullgård wrote:
quote:
> anoop_kn@yahoo.com (Anoop Kumar) writes: > > BTW -- compile with `-pthread', not `-lpthread' (though it's not directly relevant here it will avoid other potential problems). [QUOTE] > > > It's a weakness in the new NPTL thread library used by redhat 9. > pthread_kill and a few other functions cast the pthread_t to a pointer > and attempt to dereference it. Obviously, this will cause a > segmentation fault. The only workaround I can think of is not to pass > invalid thread IDs to these functions. >
--ag -- Artie Gold -- Austin, Texas




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:26 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register