![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Unverified User
Join Date: Mar 2006
Posts: 18
Rep Power: 0
![]() |
Suspending another process in win32
I am actually working in C++.net, but win API calls is what I expect I will have to use. My goal is to be able to suspend a process of which I have the Id for. I also know how to get the Id of the threads. What do I need to do to suspend the execution of that process temporarily, so that it can be resumed. I don't know any of the API programming that I will need for this, so if someone could point me in the right direction... maybe a couple of key words to search for? Thanx
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
It is not actually possible to suspend processes under windows. The closest is to suspend threads within the process e.g. if there is only one thread in the process, suspending it would effectively suspend the process. Look up the win32 API functions named SuspendThread() and ResumeThread(). If you've created the affected process using CreateThread(), you will have handles to both it's process and it's main thread.
If you are implementing both the program being suspended, as well as the program doing the suspending, you would be better off defining a means of communication so that you can tell the program to suspend itself (or, more accurately, not to do anything until you send it another message telling it to resume). This doesn't require stopping the thread in it's tracks (as with SuspendThread()); you can also simply stop it doing selected actions. This is a better approach if the program you wish to suspend has a GUI: suspending it completely would result in an apparently dead window on the screen (and make you unpopular with users). Personally, I would revisit the question of why you wish to suspend the process in the first place. By trying to do this, you are suggesting a timing dependency of your program with another, and you might be better off with another strategy (eg start the other program when you are ready for it to work to completion). |
|
|
|
|
|
#3 |
|
Unverified User
Join Date: Mar 2006
Posts: 18
Rep Power: 0
![]() |
The purpose is to allow the user to suspend any arbitrary process (like if it is being a processor/disk access hog). It will also use it for throttling disk access of other programs. Thanx for the reply and function names.
|
|
|
|
|
|
#4 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
I would also be very cautious about the notion of suspending a disk hog: doing so might be counter productive, as I/O drivers still need to manage context of a program that is trying to access the disk but has been suspended. For example, suspending a process that has opened a file can (depending on how the file is opened) mean that file is no longer accessible to other processes. A program that is simply reading from disk can be a disk hog, and not all programs open files for read-only access in a way that allows for shared access. I would not allow a user to arbitrarily suspend or change priority of any thread/processes (and neither does the task manager). In particular, fiddling with behaviour of processes that are necessary to system functioning can hurt system stability. There will be some processes whos priority cannot be changed (and cannot be suspended) because they are fundamental to workings of the operating system. Generally, users will not have the necessary access rights to change behaviour of system-owned processes. And allowing such access rights to your program would be a VERY poor idea. |
|
|
|
|
|
|
#5 |
|
Unverified User
Join Date: Mar 2006
Posts: 18
Rep Power: 0
![]() |
I have written a program which already does process priority class (I'm leaving out the name to avoid infringing any forum rules about advertisement :-). It changes process priority like task manager does, but in a more automatic fashion. I had once considered allowing the user to change thread priority, but decided that it could actually lead to instability, not to mention not really being usefull. I am working on a second version, which is why I have asked this question. I want to add some functionality to the program, to include suspending a process. There have been times which I myself have wanted to momentarily suspend a program. One such instance was waiting for a a self extracting executable (which was large, and using a lot of disk access time) and I wanted to quickly search the hardisk for another file. The search was taking forever. It would have been more efficient to suspend the extracting executable (cancelling would have forced me to start the extraction over) and let the search complete, hopefully reducing the cost of head seeking. The suspend tool wont be intended for common use, as I don't expect it to improve most computing, but in rare scenarios like this, I think it could be helpfull. Thanks again.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|