#include #include #include #include #include "iserver.h" void main(int argc, char *argv[ ]) { int childpid; int row = -1; char command_file[] = "command_file.txt"; char *b_command ; /*command to run bprobe */ char *c_command ; /*command to run cprobe */ FILE *fptr , *rptr, *cptr; int ch_cp, ch_bp, *status, *status2; char my_result_file[] = "res.txt"; char my_cprobe_file[] = "c_res.txt"; if ( (fptr = fopen(command_file, "r") ) == NULL ) printf(" Cannot open file %s \n", command_file); b_command = (char*)malloc(sizeof(command_size)); c_command = (char*)malloc(sizeof(command_size)); if ( fgets(b_command, command_size, fptr)== NULL ) printf("unable to read line from command.txt\n"); if ( fgets(c_command, command_size, fptr)== NULL ) printf("unable to read line 2 from command.txt\n"); fclose(fptr); /* if ( (rptr = fopen(my_result_file, "r") ) == NULL ) printf(" Cannot open file %s \n", my_result_file);*/ /*time_t *tp ;*/ /*time(time_t *tp);*/ /*printf("Time at start of program is: %H\n", tp->tm_hour);*/ if ( argc>2 ) printf(" Usage: Type only the program name followed by the input file name.\n"); Configure_Servers(argv[1]) ; prompt_user_for_hostname(); /* printf("Host needed is %s\n", myhost); */ if( (row = search_name(myhost)) >= 0 ) printf( "FOUND HOST %s on row= %d\n", MainPtr[row]->server_name, row); else printf("Host %s not in database\n", myhost); /*print_all_servers();*/ /******fork a child process to print Database*****/ if( (childpid = fork() ) == -1 ) { perror("can't fork"); exit(1); }else if (childpid == 0) { /* child process */ print_all_servers(); exit(0); } else { /*parent process*/ printf("parent: parent pid = %d, child pid = %d \n", getpid(), childpid) ; /******fork process to run infinite loop for BPROBE */ if( (childpid = fork() ) == -1 ) { perror("can't fork"); exit(1); }else if (childpid == 0) { /* child process BPROBE*/ printf("Infinite loop for Bprobe===+\n"); printf("command is: %s\n\n", b_command); printf("before Run_Probe func\n"); Run_Probe(b_command); printf("after Run_Probe func\n"); /* My_BProbe_Run();*/ exit(0); } else { /*parent process*/ printf("parent: parent pid = %d, child pid2 = %d \n", getpid(), childpid) ; ch_bp = wait(&status)) if (ch == childpid ){ if ( (rptr = fopen(my_result_file, "r") ) == NULL ){ printf("In main:Can't open file %s \n",my_result_file); exit(0); } while (fgets(MyBuffer, MaxLine, rptr) != NULL) { printf("!!!!!!!!!!file /tmp/res.txt :%s\n", MyBuffer); } } /******fork process to run infinite loop for CPROBE */ if( (childpid = fork() ) == -1 ) { perror("can't fork"); exit(1); }else if (childpid ==0) { /* child process CPROBE*/ printf("Infinite loop for Cprobe\n"); Run_Probe(c_command); printf("after Run_Probe func with cprobe\n"); /* My_CProbe_Run();*/ exit(0); } else { /*parent process*/ printf("parent: parent pid = %d, child pid3 = %d \n", getpid(), childpid) ; ch_cp = wait(&status2); if (ch_cp == childpid ){ if ( (cptr = fopen(my_cprobe_file, "r") ) == NULL ){ printf("In main:Can't open file %s \n",my_cprobe_file); exit(0); } while (fgets(MyBuffer, MaxLine, cptr) != NULL) { printf("!!!!!!!!!!file c_res.txt :%s\n", MyBuffer); } } /******fork process to run infinite loop for send-recv LBA multicast*/ if( (childpid = fork() ) == -1 ) { perror("can't fork"); exit(1); }else if (childpid ==0) { /* child process send-recv multicast*/ printf("Infinite loop for multicast\n"); /* Multicast_send_and_receive();*/ exit(0); } else { /*parent process*/ printf("parent: parent pid = %d, child pid4 = %d \n", getpid(), childpid) ; /*print_all_servers();*/ }/*end fork process for multicast*/ }/* end parent process before multicast */ }/* end for for Cprobe*/ }/* end parent process before cprobe*/ }/*end fork for Bprobe */