awk -- kill session

beatony發表於2012-11-21
1.第一步:使用Linux的kill命令殺死所有與oracle有關的程式。
1)查詢到與ORACLE_SID相關的oracle程式
$ ps -ef |grep $ORACLE_SID
oracle 7776 1 0 22:51 ? 00:00:00 ora_pmon_ora10g
oracle 7778 1 0 22:51 ? 00:00:00 ora_psp0_ora10g
oracle 7780 1 0 22:51 ? 00:00:00 ora_mman_ora10g
oracle 7782 1 0 22:51 ? 00:00:00 ora_dbw0_ora10g
oracle 7784 1 0 22:51 ? 00:00:00 ora_dbw1_ora10g
oracle 7786 1 0 22:51 ? 00:00:00 ora_lgwr_ora10g
oracle 7788 1 0 22:51 ? 00:00:00 ora_ckpt_ora10g
oracle 7790 1 0 22:51 ? 00:00:00 ora_smon_ora10g
oracle 7792 1 0 22:51 ? 00:00:00 ora_reco_ora10g
oracle 7794 1 0 22:51 ? 00:00:00 ora_cjq0_ora10g
oracle 7796 1 0 22:51 ? 00:00:00 ora_mmon_ora10g
oracle 7798 1 0 22:51 ? 00:00:00 ora_mmnl_ora10g
oracle 7832 1 0 22:51 ? 00:00:00 ora_arc0_ora10g
oracle 7834 1 0 22:51 ? 00:00:00 ora_arc1_ora10g
oracle 7836 1 0 22:51 ? 00:00:00 ora_qmnc_ora10g
oracle 7842 1 0 22:51 ? 00:00:00 ora_q000_ora10g
oracle 7847 1 0 22:52 ? 00:00:00 ora_q001_ora10g
oracle 7951 7592 0 23:11 pts/2 00:00:00 grep ora10g

2)去除掉包含grep命令本身的記錄
$ ps -ef |grep $ORACLE_SID |grep -v grep
oracle 7776 1 0 22:51 ? 00:00:00 ora_pmon_ora10g
oracle 7778 1 0 22:51 ? 00:00:00 ora_psp0_ora10g
oracle 7780 1 0 22:51 ? 00:00:00 ora_mman_ora10g
oracle 7782 1 0 22:51 ? 00:00:00 ora_dbw0_ora10g
oracle 7784 1 0 22:51 ? 00:00:00 ora_dbw1_ora10g
oracle 7786 1 0 22:51 ? 00:00:00 ora_lgwr_ora10g
oracle 7788 1 0 22:51 ? 00:00:00 ora_ckpt_ora10g
oracle 7790 1 0 22:51 ? 00:00:00 ora_smon_ora10g
oracle 7792 1 0 22:51 ? 00:00:00 ora_reco_ora10g
oracle 7794 1 0 22:51 ? 00:00:00 ora_cjq0_ora10g
oracle 7796 1 0 22:51 ? 00:00:00 ora_mmon_ora10g
oracle 7798 1 0 22:51 ? 00:00:00 ora_mmnl_ora10g
oracle 7832 1 0 22:51 ? 00:00:00 ora_arc0_ora10g
oracle 7834 1 0 22:51 ? 00:00:00 ora_arc1_ora10g
oracle 7836 1 0 22:51 ? 00:00:00 ora_qmnc_ora10g
oracle 7842 1 0 22:51 ? 00:00:00 ora_q000_ora10g
oracle 7847 1 0 22:52 ? 00:00:00 ora_q001_ora10g

3)使用awk命令得到我們關心的程式號
$ ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}'
7776
7778
7780
7782
7784
7786
7788
7790
7792
7794
7796
7798
7832
7834
7836
7842
7847

4)萬事俱備,我們最後使用kill命令將oracle的程式殺死,因此得到了下面完整的命令
$ ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}' | xargs kill -9

2.第二步:使用Linux的ipcs和ipcsrm命令釋放oracle佔用的共享記憶體。
1)使用ipcs命令檢視系統中共享記憶體使用情況
$ ipcs -m

------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 32768 root 644 72 2 dest
0x00000000 65537 root 644 16384 2 dest
0x00000000 98306 root 644 280 2 dest
0x00000000 131075 root 644 790528 2 dest
0x00000000 163844 root 644 790528 2 dest
0x00000000 196613 root 644 790528 2 dest
0x00000000 327689 oracle 644 790528 2 dest
0x00000000 360458 oracle 644 790528 2 dest
0x00000000 393227 oracle 644 790528 2 dest
0xecc5fba0 786447 oracle 640 5370806272 30

2)使用grep命令過濾後得到與oracle相關的內容
$ ipcs -m | grep oracle
0x00000000 327689 oracle 644 790528 2 dest
0x00000000 360458 oracle 644 790528 2 dest
0x00000000 393227 oracle 644 790528 2 dest
0xecc5fba0 786447 oracle 640 5370806272 31

2)使用awk命令獲得上面我們關心的shmid欄位內容
$ $ ipcs -m | grep oracle | awk '{print $2}'
327689
360458
393227
786447

3)最後使用ipcsrm命令釋放共享記憶體
$ ipcs -m | grep oracle | awk '{print $2}' | xargs ipcrm shm
resource(s) deleted

再次檢視一下,此時共享記憶體已經被釋放。
$ ipcs -m | grep oracle
0x00000000 327689 oracle 644 790528 2 dest
0x00000000 360458 oracle 644 790528 2 dest
0x00000000 393227 oracle 644 790528 2 dest
0x00000000 786447 oracle 640 5370806272 31 dest

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-749695/,如需轉載,請註明出處,否則將追究法律責任。

相關文章