Kills a process.
kill spid with statusonly
is the identification number of the process you want to kill. spid must be a constant; it cannot be passed as a parameter to a stored procedure or used as a local variable. Use sp_who to see a list of processes and other information.
reports on the progress of a server process ID (spid) in rollback status. It does not terminate the spid. The statusonly report displays the percent of rollback completed and the estimated length of time in seconds before the rollback completes.
Kills process number 1378:
kill 1378
Reports on the process of the rollback of spid number 13:
kill 13 with statusonly
spid: 13 Transaction rollback in progress. Estimated rollback completion:17% Estimated time left: 13 seconds
To track the progress of a rollback, you must run kill...with statusonly multiple times. If the rollback of the spid has completed when you issue kill...statusonly or if Adaptive Server is not rolling back the specified spid, kill...statusonly returns the following message:
Status report cannot be obtained. KILL spid:nn is not in progress.
Execute sp_who to get a report on the current processes, such as:
fid spid status loginame origname hostname blk dbname cmd --- ---- -------- -------- -------- -------- --- ------ ----------- 0 1 recv sleep bird bird jazzy 0 master AWAITING COMMAND 0 2 sleeping NULL NULL 0 master NETWORK HANDLER 0 3 sleeping NULL NULL 0 master MIRROR HANDLER 0 4 sleeping NULL NULL 0 master AUDIT PROCESS 0 5 sleeping NULL NULL 0 master CHECKPOINT SLEEP 0 6 recv sleep rose rose petal 0 master AWAITING COMMAND 0 7 running robert sa helos 0 master SELECT 0 8 send sleep daisy daisy chain 0 pubs2 SELECT 0 9 alarm sleep lily lily pond 0 master WAITFOR 0 10 lock sleep viola viola cello 7 pubs2 SELECT
The spid column contains the process identification numbers used in the Transact-SQL kill command. The blk column contains the process ID of a blocking process, if there is one. A blocking process (which may have an exclusive lock) is one that is holding resources that are needed by another process. In this example, process 10 (a select on a table) is blocked by process 7 (a begin transaction followed by an insert on the same table).
The status column reports the state of the command. Table 1-24 shows the status values and the effects of sp_who:
Status |
Description |
Effect of kill command |
---|---|---|
|
Waiting on a network read. |
Immediate. |
|
Waiting on a network send. |
Immediate. |
|
Waiting on an alarm, such as waitfor delay "10:00". |
Immediate. |
|
Waiting on a lock acquisition. |
Immediate. |
|
Waiting on disk I/O or some other resource. Probably indicates a process that is running, but doing extensive disk I/O. |
Process is killed when it “wakes up;” usually immediately. A few sleeping processes do not wake up, and require an Adaptive Server restart to clear. |
|
In the queue of runnable processes. |
Immediate. |
|
Actively running on one of the server engines. |
Immediate. |
|
Adaptive Server has detected a serious error condition; extremely rare. |
kill command not recommended. Adaptive Server restart probably required to clear process. |
|
A process, such as a threshold procedure, run by Adaptive Server rather than by a user process. |
Immediate; use kill with extreme care. Recommend a careful check of sysprocesses before killing a background process. |
|
Processes suspended by reaching the last-chance threshold on the log. |
Immediate. |
To get a report on the current locks and the spids of the processes holding them, use sp_lock.
In a clustered environment, a privileged Kerberos user can use the kill command to stop the spid for a DBMS task on a remote instance.
ANSI SQL – Compliance level: Transact-SQL extension.
The permission checks for kill differ based on your granular permissions settings.
Granular permissions enabled |
With granular permissions enabled, you must have the kill privilege to kill you own process, and have the kill any process privilege to kill another user's processes. |
Granular permissions disabled |
With granular permissions disabled, you must be a user with sa_role. kill privilege is not transferable. |
Commands shutdown