进程1:Test起了一个监听端口用来监听socket,端口号是5033. 在Test中调用了一个shell脚本a.sh ,在a.sh中重启了两个程序,一个是Test1,一个是Test2. Test1中有一个监听端口8888,Test2中监听端口8889 ,使用a.sh调用后,在重启Test ,这个时候发现5033端口被Test1或者Test2占用了,实际上Test1和Test2是不占用5033端口的。
求大神知道是为什么啊,有什么办法调用脚本重启Test1和Test2后,在重启Test不出现问题。
Test 中popen ,system和exec都试过了, 都有这样情况。
1.popen("RebootPro.sh &","r").
2.system("RebootPro.sh &").
3.execl("/bin/sh","sh","RebootPro.sh","&",NULL),都不行哎。
shell脚本
#!/bin/bash
ps -ef|grep Test1 |grep root|grep -v grep|awk '{print "kill -9 "$2}'|sh
cd /export/home/test/T1
nohup Test1 -d &
sleep 3
ps -ef|grep Test2 |grep root|grep -v grep|awk '{print "kill -9 "$2}'|sh
cd /export/home/test/T2
nohup Test2 -d &
sleep 3
或者大神们有什么方法用一个程序重启别的程序呢,给个例子~