1. 先看2个命令执行的结果:
[oracle@localhost ~]$ ps -ef | less
UID PID PPID C
STIME TTY TIME
CMD
oracle 469 1 0
May28 ? 00:00:05 oraclenewccs (LOCAL=NO)
oracle 495 1 1
May28 ? 05:57:23 oraclenewccs (LOCAL=NO)
oracle 863 1 1
May28 ? 05:30:25 oraclenewccs (LOCAL=NO)
oracle 1209 1 0
May28 ? 01:19:29 oraclenewccs (LOCAL=NO)
oracle 1479 1 0
May28 ? 01:30:50 oraclenewccs (LOCAL=NO)
oracle 1583 1 0
May28 ? 01:32:50 oraclenewccs (LOCAL=NO)
oracle 2234 1 0
May28 ? 00:16:05 oraclenewccs (LOCAL=NO)
oracle 2285 1 0
May28 ? 00:17:24 oraclenewccs (LOCAL=NO)
oracle 2479 1 0
May28 ? 00:20:57 oraclenewccs (LOCAL=NO)
oracle 2891 1 0
May28 ? 00:03:55 oraclenewccs (LOCAL=NO)
oracle 3213 1 0
May28 ? 00:02:55 oraclenewccs (LOCAL=NO)
oracle 3447 1 0
May28 ? 00:03:58 oraclenewccs (LOCAL=NO)
oracle 3460 1 0
May28 ? 00:00:23 oraclenewccs (LOCAL=NO)
[oracle@localhost ~]$ ps -aux | less
USER PID %CPU %MEM VSZ RSS
TTY STAT START TIME COMMAND
oracle 469 0.0 0.4 10759972 320408 ? Ss May28 0:05
oraclenewccs (LOCAL=NO)
oracle 495 1.2 10.1 10762344 7505684 ? Rs May28
356:58 oraclenewccs (LOCAL=NO)
oracle 863 1.1 10.0 10762344 7455964 ? Ss May28
330:21 oraclenewccs (LOCAL=NO)
oracle 1209 0.2 7.3 10762216 5485856 ? Ss May28 79:28
oraclenewccs (LOCAL=NO)
oracle 1479 0.3 7.5 10762344 5595556 ? Ss May28 90:49
oraclenewccs (LOCAL=NO)
oracle 1583 0.3 7.6 10761216 5679140 ? Ss May28 92:50
oraclenewccs (LOCAL=NO)
oracle 2234 0.0 5.9 10762212 4398364 ? Ss May28 16:05
oraclenewccs (LOCAL=NO)
oracle 2285 0.0 5.8 10762220 4313736 ? Ss May28 17:24
oraclenewccs (LOCAL=NO)
oracle 2479 0.0 5.9 10761176 4436164 ? Ss May28 20:57
oraclenewccs (LOCAL=NO)
注:1. ps -aux 和 ps -ef 的区别是显示的选项不一样,aux 能显示进程占用的 内存 和CPU.
2. Less 可以对返回结果上下翻动
2. 我们在服务器上用sqlplus 连接数据库,在查看进程,会多出一条记录:
oracle 16007 16006 0 10:27 ? 00:00:00
oraclenewccs (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
通过上面2个示例,我们可以看出区别在 LOCAL=NO 和 LOCAL=YES。
LOCAL=NO :非本地连接,即网络连接。 它是通过Listener 连接到服务器的。 客户端的应用通过客户端的监听向服务器的监听发送请求,服务器的监听接收后,在与数据库连接,执行相关操作,在把结果返回给客户端。 这是通过监听的流程。 所以在客户端需要配置监听,即配置tnsnames.ora。
LOCAL=YES:本地连接。 本地连接不走监听,所以在服务监听没有启动的情况下,通过本地的sqlplus 还是可以连上数据库的。
现在就有一个问题,假如我们在客户端通过PL/SQL developer 或者 Toad 工具连上服务器后,在执行sql 的过程中死掉了,我们只能结束程序,亦或者我们直接kill 掉toad 的进程,那么在服务器上并不会释放之间建立的监听进程。 没有释放的相关进程还是继续占用系统资源。 所以对于这些已经死掉的进程,我们可以kill 掉这些进程: kill -9 PID。不过在生产库上要慎用,要确认进程是死掉的才可以kill。
LOCAL=NO的进程分析处理
2008-09-01 23:26
杀死运行3天以上LOCAL=NO的进程
---------------------------------------------------------------------------------------
1.脚本
--------------------------------------------------------------------------------------
HNDBSVR-3-/opt/oracle8/tools> touch kill3DPro.sh
HNDBSVR-3-/opt/oracle8/tools> chmod +x kill3DPro.sh
HNDBSVR-3-/opt/oracle8/tools> vi kill3DPro.sh
HNDBSVR-3-/opt/oracle8/tools> cat kill3DPro.sh
#!/bin/sh
ps -e -o pid -o etime -o args|grep oracle|grep LOCAL=NO|grep ->/tmp/tmpfile
# ps -e -o pid -o etime -o args|grep oracle|grep LOCAL=NO|grep -|awk '{print $2}'|awk -F- '{print $1}'
cat /tmp/tmpfile|while read LINE
do
TIME=`echo $LINE|awk '{print $2}'`
TIME=`echo $TIME|awk -F- '{print $1}'`
if [ $TIME -gt 3 ]
then
echo $LINE|awk '{print $1}'|xargs -t -n1 kill -9
fi
done
rm -f /tmp/tmpfile
--------------------------------------------------------------------------------------
2.实例分析
--------------------------------------------------------------------------------------
ps -e -o pid -o etime -o args|grep oracle|grep LOCAL=NO
27897 4-04:45:50 oraclegpnms4 (LOCAL=NO)
2804 05:47:03 oraclegpnms4 (LOCAL=NO)
20078 01:14:52 oraclegpnms4 (LOCAL=NO)
19556 06:01:56 oraclegpnms4 (LOCAL=NO)
27855 4-04:45:52 oraclegpnms4 (LOCAL=NO)
12976 4-05:47:28 oraclegpnms4 (LOCAL=NO)
2414 05:47:51 oraclegpnms4 (LOCAL=NO)
8656 05:40:43 oraclegpnms4 (LOCAL=NO)
15656 11-06:21:13 oraclegpnms4 (LOCAL=NO)
2410 05:47:52 oraclegpnms4 (LOCAL=NO)
19083 28-11:42:58 oraclegpnms4 (LOCAL=NO)
10259 52-08:23:39 oraclegpnms4 (LOCAL=NO)
15620 11-06:21:15 oraclegpnms4 (LOCAL=NO)
20232 6-12:03:09 oraclegpnms4 (LOCAL=NO)
24844 1-07:54:46 oraclegpnms4 (LOCAL=NO)
2552 05:47:45 oraclegpnms4 (LOCAL=NO)
4338 17-19:23:28 oraclegpnms4 (LOCAL=NO)
3778 28-11:24:14 oraclegpnms4 (LOCAL=NO)
2412 05:47:52 oraclegpnms4 (LOCAL=NO)
3316 05:45:40 oraclegpnms4 (LOCAL=NO)
2939 05:46:40 oraclegpnms4 (LOCAL=NO)
3302 05:45:44 oraclegpnms4 (LOCAL=NO)
12662 30-11:37:37 oraclegpnms4 (LOCAL=NO)
24254 24-06:38:27 oraclegpnms4 (LOCAL=NO)
16504 55-13:42:30 oraclegpnms4 (LOCAL=NO)
2416 05:47:51 oraclegpnms4 (LOCAL=NO)
2530 05:47:45 oraclegpnms4 (LOCAL=NO)
2491 05:47:46 oraclegpnms4 (LOCAL=NO)
3585 05:44:53 oraclegpnms4 (LOCAL=NO)
29661 26-03:36:02 oraclegpnms4 (LOCAL=NO)
5409 02:35:57 oraclegpnms4 (LOCAL=NO)
23442 51-22:23:46 oraclegpnms4 (LOCAL=NO)
19204 3-13:14:05 oraclegpnms4 (LOCAL=NO)
10602 40-11:45:35 oraclegpnms4 (LOCAL=NO)
29541 56:16 oraclegpnms4 (LOCAL=NO)
19805 18:08 oraclegpnms4 (LOCAL=NO)
--------------------------------------------------------------------------------------
3.参数说明
--------------------------------------------------------------------------------------
ps -e -o pid -o etime -o args
-e Lists information about every process now running;
-o Prints information according to the format specifica-
tion given in format. This is fully described in
DISPLAY FORMATS. Multiple -o options can be specified;
the format specification will be interpreted as the
space-character-separated concatenation of all the
format option-arguments.
-A Lists information about all processes most frequently
requested: all those except process group leaders and
processes not associated with a terminal.
-e etime In the POSIX locale, the elapsed time since the pro-
cess was started, in the form:
[[dd-]hh:]mm:ss
args
The command with all its arguments as a string. The
implementation may truncate this value to the field
width; it is implementation-dependent whether any
further truncation occurs. It is unspecified whether
the string represented is a version of the argument
list as it was passed to the command when it started,
or is a version of the arguments as they may have been
modified by the application. Applications cannot
depend on being able to modify their argument list and
having that modification be reflected in the output of
ps. The Solaris implementation limits the string to
80 bytes; the string is the version of the argument
list as it was passed to the command when it started.
--------------------------------------------------------------------------------------
4.其它
--------------------------------------------------------------------------------------—
ps -e -o pid -o etime -o args|grep oracle|grep LOCAL=NO|grep -|awk '{print $2}'|awk -F: '{print $1}'
ps -e -o pid -o etime -o args|grep oracle|grep LOCAL=NO|grep -|awk '{print $2}'|awk -F- '{print $1}'
|