Recipe6.2.Suspending a Process


Recipe 6.2. Suspending a Process

Problem

You want to suspend a process from running. This is helpful if you want to temporarily stop an application from running, perhaps due to high CPU consumption, but you don't want to kill it. This can give you an opportunity to launch further diagnostic utilities to troubleshoot the process.

Solution

Using a graphical user interface

Open the Sysinternals Process Explorer tool (procexp.exe). To suspend a process, right-click on the target process and select Suspend. To resume a process, right-click on the target process and select Resume.

Using a command-line interface

The following command suspends a process:

> pssuspend <PID>

Replace <PID> with the process ID of the target process.

The following command resumes a suspended process:

> pssuspend -r <PID>

Using VBScript

Currently, no scripting API supports suspending processes. However, you can use the SuspendThread and ResumeThread functions that are defined in kernel.lib if you are using a high-level language such as Visual Basic or C++.

Discussion

Applications are much better behaved these days than they were a few years ago, but that still doesn't mean you won't see one from time to time peg the CPU on a system and render it virtually useless. If this happens on a remote system, it can be difficult to even use Terminal Services to access the machine. So what can you do? Well, if you can find out which process is causing the problemperhaps by using one of the methods in Recipe 6.4you can use pssuspend to remotely suspend it. You can also specify alternate credentials using the -u (user) and -p (password) options. If you specify -u without -p, it will prompt you to enter the password (this is the more secure way to do it). Here is an example command line that does this:

> pssuspend \\jamison -u rallen notepad.exe

See Also

Recipe 6.4



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net