Solved

Killing a Thread within a process.

Posted on 1998-04-14
7
4,050 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now