1 Commits

Author SHA1 Message Date
4c441cde92 Added process manager 2025-05-27 20:43:42 +02:00
3 changed files with 47 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ public:
setFlagOff();
}
guarder(guarder &g) : shmid(g.shmid) {}
void setFlagOff()
{
setFlag(false);

View File

@@ -10,6 +10,7 @@
#include "locations.h"
#include "usermanager.h"
#include "guarder.h"
#include "processManager.h"
#define MAXNAMESIZE 255
#define SCAN_DONE_SIG SIGRTMIN
@@ -86,6 +87,7 @@ int main()
int size;
char *buffer = nullptr;
processManager pm;
while (read(p1[0], &size, sizeof(int)))
{
@@ -94,12 +96,11 @@ int main()
read(p1[0], buffer, size * sizeof(char));
std::string name(buffer);
std::string cmd = std::string(SCAN_CMD_USR) + name;
std::cout << "Scan received for: " << name << std::endl;
guard.setFlagOn();
system((std::string(SCAN_CMD_USR) + name).data());
guard.setFlagOff();
pm.runTask(name, cmd);
kill(parent, SCAN_DONE_SIG);

41
src/processManager.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef _PROCCESSMANAGER_H
#define _PROCCESSMANAGER_H
#include <map>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include "guarder.h"
#include "usermanager.h"
class processManager
{
private:
std::map<std::string, guarder> running;
bool getIdTag(std::string &id)
{
return running[id].isFlagOn();
}
public:
void runTask(std::string &id, std::string &cmdCommand)
{
if (!getIdTag(id))
{
running[id].setFlagOn();
pid_t child = fork();
if (child == 0) // child
{
system(cmdCommand.c_str());
running[id].setFlagOff();
exit(EXIT_SUCCESS);
}
}
}
};
#endif // _PROCCESSMANAGER_H