?
Solved

Killing a Thread within a process.

Posted on 1998-04-14
7
Medium Priority
?
4,056 Views
Last Modified: 2013-12-26
Is there a way to kill a ind. thread within a process
0
Comment
Question by:elcoco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

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

Accepted Solution

by:
nebeker earned 450 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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