016
12.12.2003, 18:49 Uhr
~Jochen
Gast
|
Hi,
Das mit der Switch ist schon klar, nur habe ich das Problem, dass ich den ping command nicht abwarten kann und somit keinen return wert in tstat bekomme. Dies kann ich demzufolge dann auch nicht abfragen.
Jochen
C++: |
for (ii = 0; ii < MAX_PROCS; ++ii) { pid = fork(); switch(pid) { case -1: perror("fork failed"); child_running[ii] = 0; break; case 0: printf("I'm child #%d\n ", ii); int a;
/*******************************Insert a part which changes the value of done later ********************************1-254 depending on ii***************************/
a=execv("ping 192.168.0.1 -c1;a=$?;echo $a",NULL); wait(&a); //??? want to get the value 0 or 1 depending on ping /*******************************default value a = 1*****************************/ a = 1; /*******************************************************************************/
/*******************************The return value will finally be written to a *** ********************************variable a. The exit value a can than be ******** ********************************checked with tstat.*****************************/ exit(a); default: children[ii] = pid; child_running[ii] = 1; break; } }
running = MAX_PROCS; while (running) {
pid = wait(&tstat); for (ii = 0; ii < MAX_PROCS; ++ii) {
/*******************************determine which child***************************/ if (pid == children[ii]) {
/********************************child done. the success or unsuccessfull test*** *********************************of the ping command is written in**************/ valid_ip = tstat/MAX_PROCS; child_running [ii] = valid_ip; running--; printf("child ii#%d pid#%d a:%i finished\n", ii, pid,valid_ip); } } }
/********************************a loop which checks if the number is a 1 or a 0* *********************************depending on a (un)successfull ping************/ for(ii = 0; ii < MAX_PROCS; ii++){ if(child_running[ii] == 1){ printf("192.168.0.%d is a valid ip\n",ii); } else{ printf("192.168.0.%d is not a valid ip\n",ii); } } exit(0); }
|
|