sys.sysprocesses (Transact-SQL)sys.sysprocesses (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

包含正在 SQL ServerSQL Server 实例上运行的进程的相关信息。Contains information about processes that are running on an instance of SQL ServerSQL Server. 这些进程可以是客户端进程或系统进程。These processes can be client processes or system processes. 若要访问 sysprocesses,您必须位于 master 数据库上下文中,或者必须使用由三部分构成的名称 master.dbo.sysprocesses。To access sysprocesses, you must be in the master database context, or you must use the master.dbo.sysprocesses three-part name.

重要

将此 SQL Server 2000 系统表作为一个视图包含进来是为了保持向后兼容性。This SQL Server 2000 system table is included as a view for backward compatibility. 建议您改用当前的 SQL Server 系统视图。We recommend that you use the current SQL Server system views instead. 若要查找一个或多个等效系统视图,请参阅将系统表映射到系统视图 (Transact-SQL)To find the equivalent system view or views, see Mapping System Tables to System Views (Transact-SQL). 后续版本的 Microsoft SQL Server 将删除该功能。This feature will be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

列名称Column name 数据类型Data type 说明Description
spidspid smallintsmallint SQL ServerSQL Server 会话 ID。session ID.
kpidkpid smallintsmallint Windows 线程 ID。Windows thread ID.
blockedblocked smallintsmallint 正在阻塞请求的会话的 ID。ID of the session that is blocking the request. 如果此列为 NULL,则表示请求未被阻塞,或锁定会话的会话信息不可用(或无法进行标识)。If this column is NULL, the request is not blocked, or the session information of the blocking session is not available (or cannot be identified).

-2 = 阻塞资源由孤立的分布式事务拥有。-2 = The blocking resource is owned by an orphaned distributed transaction.

-3 = 阻塞资源由延迟的恢复事务拥有。-3 = The blocking resource is owned by a deferred recovery transaction.

-4 = 由于内部闩锁状态转换而无法确定阻塞闩锁所有者的会话 ID。-4 = Session ID of the blocking latch owner could not be determined due to internal latch state transitions.
waittypewaittype binary(2)binary(2) 保留。Reserved.
waittimewaittime bigintbigint 当前等待时间(毫秒)。Current wait time in milliseconds.

0 = 进程不等待。0 = Process is not waiting.
lastwaittypelastwaittype nchar(32)nchar(32) 指示上次或当前等待类型名称的字符串。A string indicating the name of the last or current wait type.
waitresourcewaitresource nchar(256)nchar(256) 锁资源的文本化表示法。Textual representation of a lock resource.
dbiddbid smallintsmallint 当前正由进程使用的数据库 ID。ID of the database currently being used by the process.
uiduid smallintsmallint 执行命令的用户 ID。ID of the user that executed the command. 如果用户数和角色数超过 32,767,则发生溢出或返回 NULL。Overflows or returns NULL if the number of users and roles exceeds 32,767.
cpucpu intint 进程的累计 CPU 时间。Cumulative CPU time for the process. 无论 SET STATISTICS TIME 选项是 ON 还是 OFF,都为所有进程更新该项。The entry is updated for all processes, regardless of whether the SET STATISTICS TIME option is ON or OFF.
physical_iophysical_io bigintbigint 进程的累计磁盘读取和写入。Cumulative disk reads and writes for the process.
memusagememusage intint 当前为此进程分配的过程缓存中的页数。Number of pages in the procedure cache that are currently allocated to this process. 一个负数,表示进程正在释放由另一个进程分配的内存。A negative number indicates that the process is freeing memory allocated by another process.
login_timelogin_time datetimedatetime 客户端进程登录到服务器的时间。Time at which a client process logged into the server.
last_batchlast_batch datetimedatetime 客户端进程上次执行远程存储过程调用或 EXECUTE 语句的时间。Last time a client process executed a remote stored procedure call or an EXECUTE statement.
ecidecid smallintsmallint 用于唯一标识代表单个进程进行操作的子线程的执行上下文 ID。Execution context ID used to uniquely identify the subthreads operating on behalf of a single process.
open_tranopen_tran smallintsmallint 进程的打开事务数。Number of open transactions for the process.
状态status nchar(30)nchar(30) 进程 ID 状态。Process ID status. 可能的值为:The possible values are:

dormant = 睡眠 SQL ServerSQL Server正在重置会话。dormant = SQL ServerSQL Server is resetting the session.

正在运行= 会话正在运行一个或多个批处理。running = The session is running one or more batches. 多个活动的结果集 (MARS) 启用后,会话可以运行多个批。When Multiple Active Result Sets (MARS) is enabled, a session can run multiple batches. 有关详细信息,请参阅使用多个活动的结果集 (MARS)For more information, see Using Multiple Active Result Sets (MARS).

背景= 会话正在运行一个后台任务,例如死锁检测。background = The session is running a background task, such as deadlock detection.

rollback = 会话具有正在处理的事务回滚。rollback = The session has a transaction rollback in process.

挂起= 会话正在等待工作线程变为可用。pending = The session is waiting for a worker thread to become available.

运行= 会话中的任务在等待获取时间量程时位于计划程序的可运行队列中。runnable = The task in the session is in the runnable queue of a scheduler while waiting to get a time quantum.

spinloop = 会话中的任务正在等待旋转锁可用。spinloop = The task in the session is waiting for a spinlock to become free.

挂起= 会话正在等待事件(如 i/o)完成。suspended = The session is waiting for an event, such as I/O, to complete.
sidsid binary(86)binary(86) 用户的全局唯一标识符 (GUID)。Globally unique identifier (GUID) for the user.
hostnamehostname nchar(128)nchar(128) 工作站的名称。Name of the workstation.
program_nameprogram_name nchar(128)nchar(128) 应用程序的名称。Name of the application program.
hostprocesshostprocess nchar(10)nchar(10) 工作站进程 ID 号。Workstation process ID number.
cmdcmd nchar (52)nchar(52) 当前正在执行的命令。Command currently being executed.
nt_domainnt_domain nchar(128)nchar(128) 客户端的 Windows 域(如果使用 Windows 身份验证)或可信连接的 Windows 域。Windows domain for the client, if using Windows Authentication, or a trusted connection.
nt_usernament_username nchar(128)nchar(128) 进程的 Windows 用户名(如果使用 Windows 身份验证)或可信连接的 Windows 用户名。Windows user name for the process, if using Windows Authentication, or a trusted connection.
net_addressnet_address nchar(12)nchar(12) 为每个用户工作站上的网络适配器分配的唯一标识符。Assigned unique identifier for the network adapter on the workstation of each user. 当用户登录时,该标识符插入 net_address 列。When a user logs in, this identifier is inserted in the net_address column.
net_librarynet_library nchar(12)nchar(12) 用于存储客户端网络库的列。Column in which the client's network library is stored. 每个客户端进程都在网络连接上进入。Every client process comes in on a network connection. 网络连接有一个与这些进程关联的网络库,该网络库使得这些进程可以建立连接。Network connections have a network library associated with them that enables them to make the connection.
loginameloginame nchar(128)nchar(128) 登录名。Login name.
context_infocontext_info binary(128)binary(128) 使用 SET CONTEXT_INFO 语句存储在批中的数据。Data stored in a batch by using the SET CONTEXT_INFO statement.
sql_handlesql_handle binary(20)binary(20) 表示当前正在执行的批或对象。Represents the currently executing batch or object.

注意此值是从对象的批或内存地址派生的。Note This value is derived from the batch or memory address of the object. 通过使用基于 SQL ServerSQL Server 哈希的算法无法计算此值。This value is not calculated by using the SQL ServerSQL Server hash-based algorithm.
stmt_startstmt_start intint 为指定 sql_handle 运行当前 SQL 语句的起始偏移量。Starting offset of the current SQL statement for the specified sql_handle.
stmt_endstmt_end intint 所指定 sql_handle 的当前 SQL 语句的结束偏移量。Ending offset of the current SQL statement for the specified sql_handle.

-1 指出当前语句为指定的 sql_handle 运行到 fn_get_sql 函数返回结果的结尾。-1 = Current statement runs to the end of the results returned by the fn_get_sql function for the specified sql_handle.
request_idrequest_id intint 请求 ID。ID of request. 用于标识在特定会话中运行的请求。Used to identify requests running in a specific session.
page_resourcepage_resource binary (8)binary(8) 适用于 :SQL Server 2019 (15.x)SQL Server 2019 (15.x)Applies to: SQL Server 2019 (15.x)SQL Server 2019 (15.x)

如果列包含页,则为页资源的8字节的十六进制表示形式 waitresourceAn 8-byte hexadecimal representation of the page resource if the waitresource column contains a page.

备注Remarks

如果用户对服务器具有 VIEW SERVER STATE 权限,则该用户可查看 SQL ServerSQL Server 实例中所有正在执行的会话;否则,该用户只能查看当前会话。If a user has VIEW SERVER STATE permission on the server, the user will see all executing sessions in the instance of SQL ServerSQL Server; otherwise, the user will see only the current session.

另请参阅See Also

与执行相关的动态管理视图和函数 (Transact-sql) Execution Related Dynamic Management Views and Functions (Transact-SQL)
将系统表映射到系统视图 (Transact-sql) Mapping System Tables to System Views (Transact-SQL)
兼容性视图 (Transact SQL)Compatibility Views (Transact-SQL)