1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /**
- * experimentQueueMain.cpp
- * - compiles to bin/queue
- * - runs through a set of controls to run the orchestrator with multiple settings over time
- *
- * Stan Gurtler
- */
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #include <cstdlib>
- #include <csignal>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- const char *ORCHESTRATOR = "bin/orchestrator";
- const char *SHUT_DOWN = "scripts/bringDownTestServers.sh";
- const int INPUT_BUFFER_LEN = 133;
- char whichTest[INPUT_BUFFER_LEN];
- int currPid = 0;
- void exitInterruptHandler(int signum)
- {
- std::cout << "Interrupt signal received, quitting." << std::endl;
- kill(-currPid, SIGINT);
- char *argv[3];
- char shutdownBuffer[INPUT_BUFFER_LEN];
- strncpy(shutdownBuffer, SHUT_DOWN, INPUT_BUFFER_LEN);
- argv[0] = shutdownBuffer;
- argv[1] = whichTest;
- argv[2] = NULL;
- int lastPid = fork();
- if (currPid < 0)
- exit(-signum);
- if (currPid == 0)
- execv(SHUT_DOWN, argv);
- else
- waitpid(lastPid, NULL, 0);
- exit(signum);
- }
- int main(int argc, char* argv[])
- {
- signal(SIGINT, exitInterruptHandler);
- char inputBuffer[INPUT_BUFFER_LEN];
- std::ifstream configFile("cfg/queue.cfg");
- while (!configFile.eof())
- {
- configFile.getline(inputBuffer, INPUT_BUFFER_LEN);
- if (strlen(inputBuffer) > 0)
- {
- char *helper = strtok(inputBuffer, " ");
- char *argv[6];
-
- char orchestratorBuffer[INPUT_BUFFER_LEN];
- strncpy(orchestratorBuffer, ORCHESTRATOR, INPUT_BUFFER_LEN);
- argv[0] = orchestratorBuffer;
- argv[1] = helper;
- strncpy(whichTest, helper, INPUT_BUFFER_LEN);
- size_t i = 2;
- while (helper != NULL && i < 6)
- {
- helper = strtok(NULL, " ");
- argv[i] = helper;
- i++;
- }
- argv[5] = NULL;
-
- currPid = fork();
- if (currPid < 0)
- {
- std::cerr << "Problem making new exec, aborting." << std::endl;
- return 1;
- }
- else if (currPid == 0)
- {
- execv(ORCHESTRATOR, argv);
- }
- else
- {
- waitpid(currPid, NULL, 0);
- }
- currPid = 0;
- }
- }
- return 0;
- }
|