| | |
which process reads the cin
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am working on a code which has several processes forked(). (linux - KDevelop)
The processes after they were created runs paralell in the background.
I want to read on a command line (like cinn >> kill=1 ) which tells the main process to kill all the childs and the main p., but I dont exactly know which process reads the input on the console.
How works the consol after forking. Which process reads the data from it?
Thanks for any suggestion.
The processes after they were created runs paralell in the background.
I want to read on a command line (like cinn >> kill=1 ) which tells the main process to kill all the childs and the main p., but I dont exactly know which process reads the input on the console.
How works the consol after forking. Which process reads the data from it?
Thanks for any suggestion.
Last edited by slacke; Jun 26th, 2007 at 2:27 pm.
The code is something like this...
but i'v got a feeling that there is something wrong in basic with that code...
for example I never get the - killing child 1.... or killing child 2...
C++ Syntax (Toggle Plain Text)
int kill=0; int proces1; int proces2; void child2() { for(int b=0; b<100; b++) { sleep(2); cout << "2" << endl; if(kill==1) { cout << "killing child 1..." << endl; proces2=0; return; } } } void child1() { for(int a=0; a<100; a++) { sleep(3); cout << "1" << endl; if(kill==1) { cout << "killing child 2..." << endl; proces1=0; return; } } } int main(int argc, char *argv[]) { int pid1, pid2; proces1 = 1; proces2 = 1; pid1 = fork(); if(pid1 == 0) { child1(); } else { cout << "forked 1" << endl; } pid2 = fork(); if(pid2==0) { child2(); } else { cout << "forked 2" << endl; } cout << "main runing" << endl; for(int clock=0; clock<100;clock++) { if(kill==0) { sleep(5); cout << "more processes needed, program runinig..." << endl; cin >> kill; } else { clock=200; } } cout << "killing signal received" << endl; sleep(10); // just for sure 10 secs for(int ok=0; ok<1000; ok++) { if(proces1==0) { cout << "process 1 killed..." << endl; if(proces2==0) { cout << "process 2 killed..." << endl; ok = 1001; } else { cout << "zombie processes stil alive..." << endl; } } } return EXIT_SUCCESS; }
but i'v got a feeling that there is something wrong in basic with that code...
for example I never get the - killing child 1.... or killing child 2...
I was trying to pass state values like kill=1, which should tell to all child processes that they should execute their ending processes and tell to the main process if it was succesful.
But I cant just pass any value to childs. I was trying with global variables (kill, processStatus1) but it did not work. Than I try pointers with same result.
How can I make this interaction between child and main processes?
But I cant just pass any value to childs. I was trying with global variables (kill, processStatus1) but it did not work. Than I try pointers with same result.
C++ Syntax (Toggle Plain Text)
int kill; int processStatus1; int main() int child1, child2, child3 ... child1 = fork();... calls the refresh function for example... child2 = fork();... calls the virtualSpace function ... and so on... kill =1;
How can I make this interaction between child and main processes?
![]() |
Similar Threads
- hacktool.rootkit virus (Viruses, Spyware and other Nasties)
- Computer dies as soon as hard drive spins up ? :-( (Troubleshooting Dead Machines)
- Use sys calls fork(),pipe(),open()..... (C)
- Need Help Of Programmers!!!! (C++)
- Homework Help, please... [cout, cin] (C++)
Other Threads in the C++ Forum
- Previous Thread: Reg Function pointers
- Next Thread: Printing binary
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets







Each process gets a handle to stdin and the computer makes sure that they all get a chance to read from it, but only one at a time.