summaryrefslogtreecommitdiff
path: root/kel_rap/c++/kel_rap.cpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-07-05 00:56:42 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-07-05 00:56:42 +0200
commit1b2029dbbbfdafb618aca3eccdbbba2512b5b49b (patch)
treee9729b2f6ece1819c6def1d736260cf234c3fe87 /kel_rap/c++/kel_rap.cpp
parent0283191ec906adaa1cb0738b5cb20044b01bb572 (diff)
downloadapps-dev_tools-main.tar.gz
kel rap for running multiple simsHEADmain
Diffstat (limited to 'kel_rap/c++/kel_rap.cpp')
-rw-r--r--kel_rap/c++/kel_rap.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/kel_rap/c++/kel_rap.cpp b/kel_rap/c++/kel_rap.cpp
new file mode 100644
index 0000000..d505125
--- /dev/null
+++ b/kel_rap/c++/kel_rap.cpp
@@ -0,0 +1,51 @@
+#include <array>
+#include <filesystem>
+#include <iostream>
+#include <string>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+namespace fs = std::filesystem;
+
+int main(int argc, char* argv[]) {
+ if (argc != 2) {
+ std::cerr << "Usage: " << argv[0] << " <dir>\n";
+ return -1;
+ }
+
+ for (const auto& e : fs::directory_iterator(argv[1])) {
+ if (!e.is_regular_file())
+ continue;
+
+ std::string path = e.path().string();
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ std::cerr << "fork failed\n";
+ return -1;
+ }
+
+ if (pid == 0) {
+ std::string path = e.path().string();
+ std::array<char*, 2> args{
+ path.data(),
+ nullptr
+ };
+
+ execvp(args[0], args.data());
+
+ std::cerr << "execvp failed: " << path << '\n';
+ return -1;
+ }
+
+ int status;
+ if (waitpid(pid, &status, 0) < 0) {
+ std::cerr << "waitpid failed\n";
+ return -1;
+ }
+ }
+
+ return 0;
+}