V$SESSION.PROCESS的解释

2605阅读 0评论2012-12-12 TOMSYAN
分类:Oracle

今天有朋友问到V$SESSION中的PROCESS是啥意思,联机文档的解释如下:

 

PROCESS

VARCHAR2(24)

Operating system client process ID

 操作系统的客户端进程ID

 但是如果我们查看PROCESS列,会发现并不像文档解释的那么明确,

这个列有2个数字组成,中间用:分割,

我们从WINDOWS SQLPLUS登陆到数据库中,然后查询PROCESS字段,就很容易发现:前面的数字是客户端进程的ID号。

C:\Documents and Settings\htaix>sqlplus scott/tiger@testdb

 

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 12 12 10:48:33 2012

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

 

连接到:

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, OLAP, Data Mining

and Real Application Testing options

 

SQL> select process

  2  from v$session where username='SCOTT';

 

PROCESS

------------------------

14612:4716

 

WINDOWS的任务管理器就很容易发现14612sqlplus的进程ID

 

 

那么4716是啥呢?

4716其实是SQLPLUS的线程ID,通过任务管理器是看不到这个号的。

 

为此我写了一个简单的小程序,用于获取指定进程号的线程ID列表:

 

输入上面的进程ID就可以看到进程14612的线程ID4716.

 


 

 

 

程序采用DELPHI编写,源码如下,有兴趣的朋友可以试试:

 

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

 

type

  TForm1 = class(TForm)

    Button2: TButton;

    Edit1: TEdit;

    Label1: TLabel;

    memo1: TMemo;

    procedure Button2Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

   uses TlHelp32;

procedure TForm1.Button2Click(Sender: TObject);

var

  FProcessEntry32: TProcessEntry32;

  ProcessID: DWord;

  ThreadHandle: THandle;

  ThreadStruct: TThreadEntry32;

begin

  ProcessID:=  strtoint(edit1.Text);

  ThreadHandle := CreateToolHelp32Snapshot(TH32CS_SnapThread,ProcessID);

  try

    ThreadStruct.dwSize := sizeOf(TThreadEntry32);

    if Thread32First(ThreadHandle, ThreadStruct) then

      repeat

        if ThreadStruct.th32OwnerProcessID = ProcessID then

          Memo1.Lines.Add(IntTostr(ThreadStruct.th32ThreadID));

      until not Thread32Next(ThreadHandle, ThreadStruct);

  finally

    CloseHandle(ThreadHandle)

  end;

end;

 

end.

 

 

上一篇:Performance Degradation as a Result of 'enq: CF - contention
下一篇:串行操作无法充分利用到临时表空间组的所有空间