- 论坛徽章:
- 0
|
ps -ef 命令经过过滤后的显示结果,此时已经运行了system().
[root@zfq152 testTeacher]# ps -ef | grep vnc | grep -v grep
root 6423 6418 0 09:48 pts/2 00:00:00 /usr/share/testTeacher/VNC_C/vncviewer/vncviewer -viewonly 199.99.99.151::21187
/************************************************************************************/
这是启动代码:
pCmd = g_strdup_printf("%s -viewonly %s::%d", DEF_VNCVIEWER_PATH, pIP, iPort);
Printf("CK,in RemoteWatchOnThread(),pCmd=%s\n", pCmd);
iRet = system(pCmd);
if((-1 == iRet) || (127 == iRet))
{
ErrMsg("system()");
exit(-1);
}
fflush(NULL);
g_free(pCmd);
/************************************************************************************/
这是一号杀手代码:
char *pCmd = NULL;
int iRet = 0;
pCmd = g_strdup_printf("ps -ef | grep vncviewer | grep -v grep | awk '{print $2}' | xargs -i kill -9 {} > /dev/null 2>&1");
iRet = system(pCmd);
if((-1 == iRet) || (127 == iRet))
{
ErrMsg("system()");
exit(-1);
}
fflush(NULL);
g_free(pCmd);
/************************************************************************************/
这是二号杀手代码
char * pCmd = NULL;
int iRet = 0;
//工作到这里,为什么会关不掉阿,他奶奶的
// pCmd = g_strdup("ps -ef | grep vncviewer | grep -v grep | awk '{print $2}' | xargs -i kill -9 {} > /dev/null 2>&1");
pCmd = g_strdup("ps -ef | grep vncviewer | grep -v grep | awk '{print $2}' | xargs -i kill -9 {} &");
if(g_pstRC != NULL)
{
g_pstRC->bOver = TRUE;
pthread_mutex_lock(&(g_pstRC->mutexOfRunVncviewer));
pthread_cond_signal(&(g_pstRC->condOfRunVncviewer));
pthread_mutex_unlock(&(g_pstRC->mutexOfRunVncviewer));
}
FILE *pFile = popen(pCmd, "w");
pclose(pFile);
/*
iRet = system(pCmd);
if((-1 == iRet) || (127 == iRet))
{
ErrMsg("system()");
exit(-1);
}
*/
Printf("CK,in RemoteControlOff(),after system(),iRet=%d\n", iRet);
g_free(pCmd);
/************************************************************************************/
这是三号杀手代码
KillPro("vncviewer");
函数的定义:
BOOL KillPro(const char *pProName)
{
assert(pProName);
char *pCmd = g_strdup_printf("ps -ef | grep %s | grep -v grep | awk '{print $2}'", pProName);
int iBufLen = 512;
char *pBuf = g_malloc0(iBufLen);
FILE *pFile = NULL;
pid_t pid = 0;
int iRet = 0;
pFile = popen(pCmd, "r");
if(pFile)
{
return FALSE;
}
fgets(pBuf, iBufLen, pFile);
pclose(pFile);
pFile = NULL;
pid = atoi(pBuf);
if(kill(pid, SIGKILL))
{//没杀死,继续追杀
ErrMsg("kill(pid, SIGKILL)");
if(kill(pid, SIGSEGV))
{//还没杀死,再杀
ErrMsg("kill(pid, SIGSEGV)");
if(kill(pid, SIGABRT))
{//竟然还没杀死,再来最后一击
ErrMsg("kill(pid, SIGABRT)");
if(kill(pid, SIGTERM))
{
return FALSE;
}
}
}
}
return TRUE;
} |
|