|
|
|
|
|
|
|
[Original]
[Print]
[Top]
|
最近在写程序的 时候 需要增加个 cli
例如执行 restart hello
我在ssh secure shell 里面输入命令sh#telnet 。。。连上程序 执行 cli_pro#restart hello ;
然后执行cli_pro#quit 并没有出现 因该有的closed那些提示和 sh# 终端就静止在那 死掉了
restart hello代码 主要就是system(“killall hello”);system(“/usr/local/sbin/hello”);
后来发现system这个函数和终端有关 会 脱离
于是我换了个方法
pid_t pid;
if ((pid=fork())<0)
{
printf ("fork error");
}
else if (pid ==0)
{
setsid();
system("killall hello");
if (execv("/usr/local/sbin/hello",NULL)<0)
{
printf("hello restart error
");
}
}
signal(SIGCHLD,SIG_IGN);
return CMD_SUCCESS;
但是这样cli终端执行quit后还是死在那里 弄不明白了
大侠们多多指教
|
|
|
[Original]
[Print]
[Top]
|
|
|