檢視阻塞的程序和被阻塞的程序

2021-10-11 01:39:23 字數 1893 閱讀 1759

----檢視阻塞的程序和被阻塞的程序

--select *

--from master..sysprocesses

--where db_name(dbid) = 'golddb'

--and spid <> @@spid

--and dbid <> 0

--and blocked >0;

--select

--request_session_id spid,

--object_name(resource_associated_entity_id) tablename

--from

--sys.dm_tran_locks

--where

--resource_type='object'

declare @spid int,@bl int,

@inttransactioncountonentry int,

@introwcount int=0,

@intcountproperties int,

@intcounter int

declare @tmp_lock_who table(

id int identity(1,1),

spid smallint,

bl smallint

)insert into @tmp_lock_who(spid,bl) select 0 ,blocked

from (select * from sysprocesses where blocked>0 ) a

where not exists(select * from (select * from sysprocesses where blocked>0 ) b

where a.blocked=spid)

union select spid,blocked from sysprocesses where blocked>0

select @intcountproperties = count(*),@intcounter = 1

from @tmp_lock_who

--if @@error<>0 return @@error

if @intcountproperties=0

begin

select '現在沒有阻塞和死鎖資訊' as message

endelse

begin

-- 迴圈開始

while @intcounter <= @intcountproperties

begin

-- 取第一條記錄

select @spid = spid,@bl = bl

from @tmp_lock_who where id = @intcounter

if @spid =0

begin

select '引起資料庫死鎖的是: '+ cast(@bl as varchar(10)) + '程序號,其執行的sql語法如下'

dbcc inputbuffer (@bl)

end

else

begin

--select '引起資料庫被鎖死的語句: '+ cast(@spid as varchar(10)) + '程序號,其執行的sql語法如下'

--dbcc inputbuffer (@spid)

select '程序號spid:'+ cast(@spid as varchar(10))+ '被' + '程序號spid:'+ cast(@bl as varchar(10)) +'阻塞,其當前程序執行的sql語法如下'

dbcc inputbuffer (@bl)

end-- 迴圈指標下移

set @intcounter = @intcounter + 1

endend

python程序阻塞

from urllib import request import os from multiprocessing import process def a print 程序a def b print 程序b if name main 結束了最後執行 p1 process target a p2 p...

程序的掛起 阻塞和睡眠

要說掛起 阻塞 睡眠難免讓人想到程序生命週期中的阻塞態或者等待狀態,而掛起和睡眠卻沒有出現在程序生命週期中,說明這三個其實在本質上區別並不那麼大,但是既然稱呼不同,應該就有不同的道理。先說阻塞,既然它能出現在程序生命週期,必然是每個程序都會經歷的乙個階段,眾所周知,程序在執行過程中必然要獲取資源,暫...

程序的阻塞和掛起的區別

程序的阻塞和掛起的區別 理解一 掛起是一種主動行為,因此恢復也應該要主動完成,而阻塞則是一種被動行為,是在等待事件或資源時任務的表現,你不知道他什麼時候被阻塞 pend 也就不能確切 的知道他什麼時候恢復阻塞。而且掛起佇列在作業系統裡可以看成乙個,而阻塞佇列則是不同的事件或資源 如訊號量 就有自己的...