LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-31-2009, 02:31 PM   #1
onewebclick
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Rep: Reputation: 0
Question Is there a way to kill or suspend a thread/task in a multithreaded process ?


Is there a way to kill or suspend a thread in a multithreaded process ? for(eg) in java which is a multithreaded process , if i do a kill -STOP <tid> it stops the entire process neither the kill -9 <tid> kills the entire process instead of a particular thread . Is there any trick to just suspend or kill the thread ?
 
Old 08-31-2009, 09:28 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
You can't kill or stop just one thread from another process.

You can send a signal to a particular thread, but the stop/abort action that is taken by the signal affects the whole process.

In the earlier implementation of Linux threads, it was possible to stop a single thread with SIGSTOP, but this behaviour has now been fixed to conform to the Posix standard (so it stops all threads in the process).

You can use pthread_cancel to stop a thread. But this is done from within the same process space.
 
Old 09-01-2009, 09:29 AM   #3
onewebclick
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by neonsignal View Post
You can't kill or stop just one thread from another process.

You can send a signal to a particular thread, but the stop/abort action that is taken by the signal affects the whole process.

In the earlier implementation of Linux threads, it was possible to stop a single thread with SIGSTOP, but this behaviour has now been fixed to conform to the Posix standard (so it stops all threads in the process).

You can use pthread_cancel to stop a thread. But this is done from within the same process space.
How about using any debugger like gdb or dbx , is it possible to stop after attaching to the process, maybe probably calling the pthread_cancel() method or something. or set a breakpoint on most commonly used methods by a process to break the thread and stop , any thoughts ?
 
Old 09-02-2009, 01:21 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Why and under what circumstances are you trying to do this?
 
Old 09-02-2009, 11:18 PM   #5
onewebclick
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
Why and under what circumstances are you trying to do this?
If a thread goes into somekind kind of loop causing the CPU to spike , I would like to suspend or kill the thread instead of killing the entire process.
 
Old 09-03-2009, 12:04 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Well, theoretically, if you have a the main ctrl thread to respond to (ie catch) say

kill USR1

which is an unassigned signal for use by programmers, you could get the ctrl thr to read a cfg file where you've set the thread id to be stopped (pthread_cancel), but I can't see how you'd id that thread. Possibly you can tell externally eg separate logs for each thread?

IOW, first you need some way for you or the ctrl thr itself to notice you've got a runaway and second you need to be able to id which thread it is.
 
  


Reply

Tags
kill, linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel panic attempted to kill the idle task! in idle task - not syncing dudutworld Linux - Newbie 2 09-16-2013 01:50 PM
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 09:42 AM
[SOLVED] Kill a hung task when kill -9 doesn't help 10110111 Linux - General 4 04-02-2009 11:10 AM
Does killing the thread kill its parent process? piyush.kansal Programming 7 07-09-2007 08:11 PM
Multithreaded System On 4 Cpu Linux Machine, process stuck on certain thread eyalzm Programming 1 05-10-2004 11:46 AM


All times are GMT -5. The time now is 07:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration