I wrote code with client code in which I have many connections, and let each node represent a different process on the same computer. And for this I obviously use fork ().
But now the problem is that all the results are displayed on one terminal. I want to know if there is a way that after each fork() or process creation, a new terminal opens, and all the results will be displayed for this process on a specific terminal.
PS: I tried system("gnome-terminal") , but it just opens a new terminal, but all the results are displayed again on the same terminal. All new terminals simply open and remain empty without any results.
I also clicked on this link. How to call the program output of another terminal for output in C on Linux , but I do not want to run my program with parameters or something else, It should be exactly the same as ./test
Here is my code: -
for(int i=0;i<node-1;i++) { n_number++; usleep(5000); child_pid[i]=fork(); if(!child_pid[i]) { system("gnome-terminal"); file_scan(); connection(); exit(0); } if(child_pid[i]<0) printf("Error Process %d cannot be created",i); } for(int i=0;i<node-1;i++) wait(&status);
So basically I want for each process there should be a new terminal displaying only this process information or result.
What I definitely want:
- After fork () I have some data related to the say 1 process, then I want its output to be on the same terminal
- The same thing happens with every process. So if I have 3 processes, then there should be 3 terminals, and each should only display process related data.
I know that this can be done using IPC (Inter Process Communication), but is there any other way? I mean just 2-3 teams or so? Because I do not want to invest too much in coding this part.
Thanks in advance!
source share