Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2837790
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: Oracle

2012-12-12 11:31:58

今天有朋友问到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.

 

 

阅读(2380) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~