UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2007-07-11 10:37 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: THread & process

if I want to kill a thread in a process from another process ,how can I do? what kinds of methods can I use?

Offline

#2 2007-07-12 01:06 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: THread & process

I'm not sure such a thing is possible...  At least not everywhere, portably...  On
Linux, I believe you can possibly use tkill() to do this, if you know the thread ID to
send to...  There's also a pthread_kill(), but I'm pretty sure that is only intended for
calling by other members of the same thread group, not some external process...

Offline

#3 2007-07-13 03:01 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: THread & process

how can I make a thread group ?what function can use? and how I can kill another thead in the thread group?

Offline

#4 2007-07-13 12:55 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: THread & process

What??  By "thread group", I just mean the group of threads that together constitute
a single logical process, working together, sharing their address space with each
other...  In other words, just "a multi-threaded process"...  So, I don't understand your
questions...  You create one by simply creating threads within your process...
Typically, with pthread_create()...  And, I already told you how to kill a thread inside
your own process: pthread_kill()...  This is using "kill" in the loose sense, of course,
meaning to hit with a signal...  If, however, you do something silly and send it a
SIGKILL or something, then you'll probably end up taking down the entire process
(and all threads in it)...  What you would need to have happen is for the thread that
gets hit to call pthread_exit() voluntarily, if you wish the thread to stop running...

Offline

#5 2007-07-14 06:43 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: THread & process

what are differences between the pthread_kill() and pthread_exit()?
under what situation I can use pThread_exit()?

Offline

#6 2007-07-14 12:00 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: THread & process

Did you read the manpages at all, or what?

Offline

#7 2007-07-14 07:12 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: THread & process

Yeah, really: you do realize there's a "man" command don't you??

The difference between pthread_kill() and pthread_exit() is exactly the same as
the difference between kill() and exit()...  Namely one sends a signal to another
thread/process, while the other exits the current thread/process...  They are only
related at all by virtue of being the same library...  Otherwise, their functions are
completely different...  Your question might as well have asked what is the difference
between strcmp() and sprintf()...  They're just not directly comparable in any way...

Offline

#8 2007-07-15 02:01 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: THread & process

oh,  I think pthread_kill() and pthread_exit() all can terminate a thread,
and under what situation I can use pthread_exit() or pthread_kill()?

Offline

#9 2007-07-15 05:52 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: THread & process

Offline

#10 2007-07-16 04:20 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: THread & process

oh ,when I must  only use pthread_exit() to terminate a thread?  whether this function must appear inside one thread?

Offline

#11 2007-07-16 01:20 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: THread & process

I can't parse that question...

pthread_exit() terminates the calling thread...  I'm not sure if you're not getting that,
or what...

Maybe you want to look into pthread_cancel()?  That's another possible way of
terminating some other thread...

Offline

#12 2007-07-17 10:46 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: THread & process

I want to know whether the effect of using  pthread_kill() and pthread_exit() to terminate a thread is the same? if not ,what are the differences?
  thanks.

Offline

#13 2007-07-17 11:08 AM

biologz
Administrator
From: Puking on the pavement
Registered: 2005-11-02
Posts: 396

Re: THread & process


gethostbyintuition() is still a dream of mine

                                                 -- quoted from bash

Offline

Board footer

Powered by FluxBB