清理远程桌面软件NX死session留下的进程
2012-06-06 15:31
337 查看
系统:redHat 5.5
背景:开发人员通过远程桌面软件NX连接linux服务器完成他们的设计工作,但是NX有些时候会出现些BUG,开发人员非正常关其PC机、或者其它特殊情况导致其不能恢复以前的连接的NX session. 然而以前的NX session却在服务器端保留,包括在这个session中运行的程序,这样导致服务器资源浪费和产生僵尸进程。
解决方法:运行命令 w -h,分析后发现,每个正常运行的NX session都会记录下用户名、端口号和远程连接IP,而每个正常运行的NX session里开的每个terminal都会关联NX session的端口号。 这样便可以抓出每个用户所有terminal对应的端口号和当前正常的端口号做对比,不同的就判断为有死NX session留下的,将其kill掉。(不好意思,不方便贴图)
使用方法:cron定期运行NXclean.sh将所有用户的死NX session留下脚本全杀掉,只保留当前活动状态的NX session.
具体脚本:NXclean.sh
注:脚本为手动输入,如有错,请通知我更正。
本文出自 “简单至上” 博客,请务必保留此出处http://root123.blog.51cto.com/3109439/890265
背景:开发人员通过远程桌面软件NX连接linux服务器完成他们的设计工作,但是NX有些时候会出现些BUG,开发人员非正常关其PC机、或者其它特殊情况导致其不能恢复以前的连接的NX session. 然而以前的NX session却在服务器端保留,包括在这个session中运行的程序,这样导致服务器资源浪费和产生僵尸进程。
解决方法:运行命令 w -h,分析后发现,每个正常运行的NX session都会记录下用户名、端口号和远程连接IP,而每个正常运行的NX session里开的每个terminal都会关联NX session的端口号。 这样便可以抓出每个用户所有terminal对应的端口号和当前正常的端口号做对比,不同的就判断为有死NX session留下的,将其kill掉。(不好意思,不方便贴图)
使用方法:cron定期运行NXclean.sh将所有用户的死NX session留下脚本全杀掉,只保留当前活动状态的NX session.
具体脚本:NXclean.sh
#!/bin/bash # #author:root123.blog.51cto.com #description: kill all the processes left by dead NX session. # logFile=./nxclean.log #get the users' names who had logined system. users=$(w -h | awk '{print $1}' | sort -u) for i in $users do #get current NX port number of each user NXport=$(w -h | grep "^$i" | awk '{print $2}' | grep "^:[0-9]") NXport=${NXport#":"} #get all exist NX port number of each user existPorts=$(w -h | grep "^$i" | awk '{print $3}' | grep "^:[0-9]" | sort -u) for j in $existPorts do if [ X$j =X ] then : else existPort=${j%".0"} existPort=${j#":"} #kill all processes which related the existsPort; NX port is greater than or equal 1000 if [ X${existPort != X${NXport} } && [ ${existPort} -ge 1000 ] then echo "$(date) $(hostname) user is $i, current NX port is $NXport, dead NX port is $existPort" >> $logFile echo "kill all the processes which related the dead NX prot $existPort" >> $logFile #get the PID related $existPort TTYs=$(w -h | grep $i | grep $existPort | awk '{print $2}') for k in $TTYs do PIDs=$(ps axu | grep "^$i" grep "$k" | awk '{print $2}') for l in $PIDs do if [ X$l != "X" ] then echo "kill process $l" >> $logFile kill -9 $l fi done done fi fi done done
注:脚本为手动输入,如有错,请通知我更正。
本文出自 “简单至上” 博客,请务必保留此出处http://root123.blog.51cto.com/3109439/890265
相关文章推荐
- linux下远程桌面控制软件---NX
- 远程桌面软件
- [软件] 一款优秀的远程桌面连接管理软件Remote Desktop Organizer
- 终于找到一个类似wince 远程桌面控制android设备的软件——Androidscreencast
- fedora下的远程桌面软件--rdesktop
- 【一步一步走(1)】远程桌面软件VNC的安装与配置
- 使用方便的多功能远程桌面软件-mRemote
- Linux远程桌面NX_Server
- Linux下安装FreeRDP,连接windows远程桌面的好软件
- 远程桌面连接指定会话(Session)
- 树莓派开发系列教程5——树莓派常用软件及服务(vi、远程桌面、ssh、samba、u盘)
- 您不能初始化一个远程桌面连接,因为远程计算机上的windows登录软件被不兼容的软件MyGina.dll取代
- Mac上使用远程桌面软件连接Windows或Linux
- Linux远程连接windows桌面和screen后台虚拟终端进程管理
- FinalShell SSH客户端,服务器管理,远程桌面加速软件,支持Windows,Mac OS
- 安装Ubuntu轻量级远程桌面,内存占用极小,速度远超VNC和NX
- CentOS6.5下安装远程桌面服务端软件VNC Server
- Windows远程桌面控制Linux软件Xmanager配置
- 路由器_内网端口映射,nat_端口映射_工具_软件_远程桌面_连接_端口_花生壳_个人_FTP_服务器_WEB站点