清理数据库连接线程

简介: CREATE proc usp_clr_SessionasbeginDECLARE @spid INT,@strSql VARCHAR(200),@pid intif object_id('tempdb.
 
 
CREATE proc usp_clr_Session
as
begin
DECLARE @spid INT , @strSql VARCHAR ( 200 ), @pid int

if object_id ( ' tempdb..#temp ' ) is not null
drop table # temp
create table # temp
(
id
int identity ( 1 , 1 ) not null
,Proc_info
varchar ( 8000 ) null
)
-- insert data into temp table
insert into # temp (Proc_info)
exec master..xp_cmdshell ' tasklist /v /fi "imagename eq clinkivr.exe" '

-- delete the wrong records
delete from # temp
where Proc_info is null or Proc_info like ' %==========% ' or ID = 2

select @pid = isnull ( max (dbo.F_split_V2(Proc_info, 2 )) , - 1 )
from # temp

print ( @pid )

DECLARE clr_sp_cursor CURSOR FOR
SELECT SPID
FROM master..sysprocesses
WHERE cmd = ' AWAITING COMMAND ' AND dbid > 4 AND status = ' sleeping ' and hostprocess = @pid

OPEN clr_sp_cursor;

FETCH NEXT FROM clr_sp_cursor
INTO @spid ;

WHILE @@FETCH_STATUS = 0
BEGIN
SET @strSql = ' kill ' + RTRIM ( @spid )
PRINT ( @strsql )
EXEC ( @strsql )
FETCH NEXT FROM clr_sp_cursor
INTO @spid ;
END
CLOSE clr_sp_cursor;
DEALLOCATE clr_sp_cursor;

end
GO
 
   
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

/*
select * FROM master..sysprocesses where hostprocess = 3368 order by cpu desc

master..xp_cmdshell 'tasklist /v'
*/

-- ALTER a splite function
Create function F_split_V2( @S nvarchar ( 4000 ), @i int )
returns nvarchar ( 100 )
as
begin
if @i = 1 -- Image_name
begin
if patindex ( ' %.exe% ' , @s ) = 0
set @s = rtrim ( left ( @s , patindex ( ' %[0-9]% ' , @s ) - 1 ))
else
set @s = rtrim ( left ( @s , patindex ( ' %.exe% ' , @s ) + 4 ))
end
else if @i = 2 -- Pid
begin
if patindex ( ' %.exe% ' , @s ) = 0
set @s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
else
set @s = ltrim ( substring ( @s , patindex ( ' %.exe% ' , @s ) + 4 , len ( @s )))

select @s = rtrim ( left ( @s , patindex ( ' %[^0-9]% ' , @s ) - 1 ))
end
else if @i = 3 -- Session_name
begin
if patindex ( ' %.exe% ' , @s ) = 0
set @s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
else
set @s = ltrim ( substring ( @s , patindex ( ' %.exe% ' , @s ) + 4 , len ( @s )))
select @s = stuff ( @s , 1 , patindex ( ' %[^0-9]% ' , @s ) - 1 , '' ),
@s = rtrim ( left ( @s , patindex ( ' %[0-9]% ' , @s ) - 1 ))
end
else if @i = 4 -- Session#
begin
if patindex ( ' %.exe% ' , @s ) = 0
set @s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
else
set @s = ltrim ( substring ( @s , patindex ( ' %.exe% ' , @s ) + 4 , len ( @s )))
select @s = stuff ( @s , 1 , patindex ( ' %[^0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
,
@s = rtrim ( left ( @s , patindex ( ' % % ' , @s ) - 1 ))
end
else if @i = 5 -- memory
begin
if patindex ( ' %.exe% ' , @s ) = 0
set @s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
else
set @s = ltrim ( substring ( @s , patindex ( ' %.exe% ' , @s ) + 4 , len ( @s )))

select @s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[^0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[1-9]% ' , @s ) - 1 , '' )
,
@s = rtrim ( left ( @s , patindex ( ' %k% ' , @s ) - 1 ))
end
else if @i = 6 -- user_name
select @s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[^0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[0-9]% ' , @s ) - 1 , '' )
,
@s = stuff ( @s , 1 , patindex ( ' %[1-9]% ' , @s ) - 1 , '' )
,
@s = rtrim ( substring ( @s , patindex ( ' %\% ' , @s ) + 1 , 18 ))
else if @i = 7 -- cup_time
select
@s = substring ( @s , patindex ( ' %[0-9]:[0-9][0-9]:[0-9][0-9]% ' , @s ), 8 )
else
select @s =right ( @s , charindex ( ' ' , reverse ( @s ), 3 ) - 1 )
return @s
end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
目录
相关文章
|
6月前
|
人工智能 网络性能优化 调度
Koordinator v1.6: 支持AI/ML场景的异构资源调度能力
如何高效管理和调度这些资源成为了行业关注的核心问题。在这一背景下,Koordinator积极响应社区诉求,持续深耕异构设备调度能力,并在最新的v1.6版本中推出了一系列创新功能,帮助客户解决异构资源调度难题。
|
Web App开发 安全 Linux
FFmpeg开发笔记(二十六)Linux环境安装ZLMediaKit实现视频推流
《FFmpeg开发实战》书中介绍轻量级流媒体服务器MediaMTX,但其功能有限,不适合生产环境。推荐使用国产开源的ZLMediaKit,它支持多种流媒体协议和音视频编码标准。以下是华为欧拉系统下编译安装ZLMediaKit和FFmpeg的步骤,包括更新依赖、下载源码、配置、编译、安装以及启动MediaServer服务。此外,还提供了通过FFmpeg进行RTSP和RTMP推流,并使用VLC播放器拉流的示例。
1068 3
FFmpeg开发笔记(二十六)Linux环境安装ZLMediaKit实现视频推流
谷歌浏览器下载的内容老是自动打开
原因是每次下载内容在浏览器左下角都有提示,一般都是选择打开所在文件夹,一次手残,点了总是打开此文件导致一下载文件就自动打开。
1321 0
谷歌浏览器下载的内容老是自动打开
【接口自动化】selenium库也有大用场(获取cookie)
【接口自动化】selenium库也有大用场(获取cookie)
【接口自动化】selenium库也有大用场(获取cookie)
|
Java 程序员 Linux
Apache Maven ToolChains的使用
Apache Maven ToolChains的使用
Apache Maven ToolChains的使用
|
SQL 安全 数据可视化
齐博cms最新SQL注入网站漏洞 可远程执行代码提权
齐博cms整站系统,是目前建站系统用的较多的一款CMS系统,开源,免费,第三方扩展化,界面可视化的操作,使用简单,便于新手使用和第二次开发,受到许多站长们的喜欢。开发架构使用的是php语言以及mysql数据库,强大的网站并发能力。于近日,我们SINE安全公司发现齐博cms又爆出高危的sql注入漏洞,关于该网站漏洞的详情,我们来详细的分析漏洞的产生以及如何利用。
715 0
齐博cms最新SQL注入网站漏洞 可远程执行代码提权
|
Oracle 关系型数据库 Shell
【DBCA -SILENT】静默方式安装11gR2 oracle数据库软件
【DBCA -SILENT】静默方式安装11gR2数据库软件单实例 BLOG文档结构图         相关文章链接:     DBCA静默方式建库 :http://blog.
1455 0
|
1天前
|
人工智能 运维 安全