从SQL Server检查后台进程 [英] Check background process from SQL Server

查看:251
本文介绍了从SQL Server检查后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个后台进程,可以在任务管理器运行时看到它.我需要从数据库中检查该进程是否正在运行 我已经尝试过以下查询

I have a background process running, it can be seen in task Manager while its running. I need to check from my database, whether the process is running or not I have tried the following query

select * from sys.dm_os_threads
select * FROM sys.dm_os_tasks

但是它并没有显示所有正在系统上运行的进程

But it doesnt show me all process running on the system

推荐答案

因此,您似乎不是在查看SQL Server进程,而是在计算机上为另一个应用程序看到了另一个进程,而没有内置的DMV或函数就能向您显示此信息.您有两种选择,一种是编写CLR存储的proc或函数来检查进程,另一种是使用xp_cmdshell获取任务列表,您可以像这样进行操作:

So it looks like you're not trying to see a SQL server process but another process on the machine for another application, none of the built in DMVs or functions will be able to show you this information natively. You have a couple of options, one is to write a CLR stored proc or function to check for the process, the other is to use xp_cmdshell to get the tasklist, you can do that like this:

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
GO
EXEC xp_cmdshell 'tasklist.exe'
GO
EXEC sp_configure 'xp_cmdshell', 0
RECONFIGURE

这将列出计算机上所有正在运行的进程,如果需要的话,您可以将该数据推入表中以进行进一步分析,或者可以使用tasklist.exe参数来查找您所需要的进程感兴趣.请记住,只要不需要xp_cmdshell即可,因为它可能会带来安全风险.

That will list out all the running processes on the machine, you could shove that data into a table if you like for further analysis if required, or you can play with the tasklist.exe parameters to just look for the process that you are interested in. Just remember to turn off xp_cmdshell whenever you don't need it as it can be a security risk.

这篇关于从SQL Server检查后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆