Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 19th, 2006, 6:54 PM   #1
coder0xff
Unverified User
 
coder0xff's Avatar
 
Join Date: Mar 2006
Posts: 18
Rep Power: 0 coder0xff is on a distinguished road
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
coder0xff is offline   Reply With Quote
Old May 19th, 2006, 7:16 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
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).
grumpy is offline   Reply With Quote
Old May 19th, 2006, 7:58 PM   #3
coder0xff
Unverified User
 
coder0xff's Avatar
 
Join Date: Mar 2006
Posts: 18
Rep Power: 0 coder0xff is on a distinguished road
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.
coder0xff is offline   Reply With Quote
Old May 20th, 2006, 4:27 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by coder0xff
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.
I wouldn't write a program to do that: use the windows task manager to lower the priority of the offending process. Process priority is used by the windows scheduler to determine what CPU resources (in particular) are made available to each program. It is possible to do that programatically (e.g. SetPriorityClass() function for controlling priority of a process), but functionally you can't do much more than can be done with the task manager.

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.
grumpy is offline   Reply With Quote
Old May 28th, 2006, 12:33 PM   #5
coder0xff
Unverified User
 
coder0xff's Avatar
 
Join Date: Mar 2006
Posts: 18
Rep Power: 0 coder0xff is on a distinguished road
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.
coder0xff is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC