I am writing server and client socket program .
The server manages connections between clients.
When client wants to chat with another I open new terminal screen using :
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.
Because I want to try something like this: When client wants to chat with another friend he tells the server and automatically the terminal with the last one close .
So I have to write here command which kill the process that open last terminal chat screen.
Is there any way to know from this block the number of process which have this new terminal.
No; replace it with:
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.
}