Solved

Killing a Thread within a process.

Posted on 1998-04-14
7
4,051 Views
Last Modified: 2013-12-26
Is there a way to kill a ind. thread within a process
0
Comment
Question by:elcoco
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:elcoco
ID: 1292145
Edited text of question
0
 
LVL 5

Accepted Solution

by:
nebeker earned 150 total points
ID: 1292146
Depends if you own the thread or not....

DosKillThread() will toast any thread that your process created.  However, it is not exactly recommended because it does not allow the thread to do any cleanup work before it exits.

I also remember some hazards using DosKillThread to toast threads that were created with beginthread instead of DosCreateThread...

The best way is to set some kind of notification flag for the thread, and let it do its cleanup and then exit.

If you are trying to kill an individual thread from another process, then I don't know how to do it.  You might be out of luck....

You also might want to mention *why* you want to kill a thread - there might be a better way of doing it than just destroying the thread...
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1292147
More info please!
what's an 'ind. thread'?
Are you in the same process?
Do you have the process ID?
Does the thread need to do any cleanup?
Is the thread likley to terminate itsself? (ran into this one, OS/2 reuses thread IDs so if you ask thread N to die, and it does, and another  one starts with thread ID N, and then you kill thread ID N thinking it;s the original one still hanging around, you;re in trouble!)

The quick answer is DosKillThread()

0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:elcoco
ID: 1292148
thanks, i have an oem package that is creating threads but not cleaning them up. therefore i eventually run out of avail. threads.  the manufact. is slow to resolve this is.  i'm trying to either create a work around or another app. that could close threads that have been inactive. i dont know if this is possible from your answer....would be grateful for any help you can provide
0
 
LVL 5

Expert Comment

by:nebeker
ID: 1292149
As far as I know, one process cannot kill individual threads from another process.

If you were to shut down the offending process, all of its dead threads would go along with it.  Is there any way you can "restart" the problematic program every once in a while?  (Kind of like the trick used to keep Windows NT servers running - reboot them every night at midnight <g>)

In order for your system to truly run out of available threads, this process must be creating hundreds of them....  How long does it take to run out, and how many threads are in the system when it finally dies?
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1292150
Another problem qould be determining which of th threads are idle.
Why not just bump up the threads to the max (4095)?
That should keep the app busy chewing them up for a while.

0
 

Author Comment

by:elcoco
ID: 1292151
Thanks, i have already bumped them up to 4095...the app does open quite a bit of
 threads. its opening an sql table and writing to an ascii file. it will open a thread for each
read AND write. it does this hourly for approx. 40 files with two data pieces a piece and the threads are exhausted after a few days....i can reboot this system,but the problem becomes automating the process. i guess i can figure something out. since i dont have the source code i cant fix and recompile.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 137
List out all word 7 296
viewing source code from eclipse 13 108
centeredAverage challenge 8 167
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question