experimentQueueMain.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * experimentQueueMain.cpp
  3. * - compiles to bin/queue
  4. * - runs through a set of controls to run the orchestrator with multiple settings over time
  5. *
  6. * Stan Gurtler
  7. */
  8. #include <iostream>
  9. #include <fstream>
  10. #include <cstring>
  11. #include <cstdlib>
  12. #include <csignal>
  13. #include <unistd.h>
  14. #include <sys/types.h>
  15. #include <sys/wait.h>
  16. const char *ORCHESTRATOR = "bin/orchestrator";
  17. const char *SHUT_DOWN = "scripts/bringDownTestServers.sh";
  18. const int INPUT_BUFFER_LEN = 133;
  19. char whichTest[INPUT_BUFFER_LEN];
  20. int currPid = 0;
  21. void exitInterruptHandler(int signum)
  22. {
  23. std::cout << "Interrupt signal received, quitting." << std::endl;
  24. kill(-currPid, SIGINT);
  25. char *argv[3];
  26. char shutdownBuffer[INPUT_BUFFER_LEN];
  27. strncpy(shutdownBuffer, SHUT_DOWN, INPUT_BUFFER_LEN);
  28. argv[0] = shutdownBuffer;
  29. argv[1] = whichTest;
  30. argv[2] = NULL;
  31. int lastPid = fork();
  32. if (currPid < 0)
  33. exit(-signum);
  34. if (currPid == 0)
  35. execv(SHUT_DOWN, argv);
  36. else
  37. waitpid(lastPid, NULL, 0);
  38. exit(signum);
  39. }
  40. int main(int argc, char* argv[])
  41. {
  42. signal(SIGINT, exitInterruptHandler);
  43. char inputBuffer[INPUT_BUFFER_LEN];
  44. std::ifstream configFile("cfg/queue.cfg");
  45. while (!configFile.eof())
  46. {
  47. configFile.getline(inputBuffer, INPUT_BUFFER_LEN);
  48. if (strlen(inputBuffer) > 0)
  49. {
  50. char *helper = strtok(inputBuffer, " ");
  51. char *argv[6];
  52. char orchestratorBuffer[INPUT_BUFFER_LEN];
  53. strncpy(orchestratorBuffer, ORCHESTRATOR, INPUT_BUFFER_LEN);
  54. argv[0] = orchestratorBuffer;
  55. argv[1] = helper;
  56. strncpy(whichTest, helper, INPUT_BUFFER_LEN);
  57. size_t i = 2;
  58. while (helper != NULL && i < 6)
  59. {
  60. helper = strtok(NULL, " ");
  61. argv[i] = helper;
  62. i++;
  63. }
  64. argv[5] = NULL;
  65. currPid = fork();
  66. if (currPid < 0)
  67. {
  68. std::cerr << "Problem making new exec, aborting." << std::endl;
  69. return 1;
  70. }
  71. else if (currPid == 0)
  72. {
  73. execv(ORCHESTRATOR, argv);
  74. }
  75. else
  76. {
  77. waitpid(currPid, NULL, 0);
  78. }
  79. currPid = 0;
  80. }
  81. }
  82. return 0;
  83. }