如何从 C 中的程序关闭 gnome 终端屏幕
How to close gnome terminal screen from program in C
我正在编写服务器和客户端套接字程序。
服务器管理客户端之间的连接。
当客户想与另一个人聊天时,我使用以下命令打开新的终端屏幕:
char command[MAXBUFSIZE];
strcpy(command,"gnome-terminal -e './client ");
strcat(command,client.url);
strcat(command," ");
strcat(command,client.port);
strcat(command," '");
system(command);
有没有办法从这个块中知道有这个新终端的进程数。
因为我想尝试这样的事情:
当客户想和另一个朋友聊天时,他告诉服务器并自动关闭最后一个终端。
所以我必须在这里写命令来终止打开最后一个终端聊天屏幕的进程。
Is there any way to know from this block the number of process which
have this new terminal.
否;将其替换为:
char command[MAXBUFSIZE];
sprintf(command, "./client %s %s", client.url, client.port);
pid_t pid = fork();
switch (pid)
{ int status;
case -1: perror("fork");
break;
case 0: execlp("gnome-terminal", "gnome-terminal", "-e", command, NULL);
perror("exec");
exit(1);
default: // You may kill the new terminal process "pid", as you wish.
// wait(&status); if you want to.
}
我正在编写服务器和客户端套接字程序。
服务器管理客户端之间的连接。
当客户想与另一个人聊天时,我使用以下命令打开新的终端屏幕:
char command[MAXBUFSIZE];
strcpy(command,"gnome-terminal -e './client ");
strcat(command,client.url);
strcat(command," ");
strcat(command,client.port);
strcat(command," '");
system(command);
有没有办法从这个块中知道有这个新终端的进程数。
因为我想尝试这样的事情: 当客户想和另一个朋友聊天时,他告诉服务器并自动关闭最后一个终端。
所以我必须在这里写命令来终止打开最后一个终端聊天屏幕的进程。
Is there any way to know from this block the number of process which have this new terminal.
否;将其替换为:
char command[MAXBUFSIZE];
sprintf(command, "./client %s %s", client.url, client.port);
pid_t pid = fork();
switch (pid)
{ int status;
case -1: perror("fork");
break;
case 0: execlp("gnome-terminal", "gnome-terminal", "-e", command, NULL);
perror("exec");
exit(1);
default: // You may kill the new terminal process "pid", as you wish.
// wait(&status); if you want to.
}