+void StopScriptExecuter(int msgID)
+{
+STG_LOGGER & WriteServLog = GetStgLogger();
+
+for (int i = 0; i < 5; ++i)
+ {
+ struct msqid_ds data;
+ if (msgctl(msgID, IPC_STAT, &data))
+ {
+ int e = errno;
+ printfd(__FILE__, "StopScriptExecuter() - msgctl for IPC_STAT failed: '%s'\n", strerror(e));
+ WriteServLog( "Failed to check queue emptiness: '%s'", strerror(e));
+ break;
+ }
+
+ WriteServLog("Messages in queue: %d", data.msg_qnum);
+
+ if (data.msg_qnum == 0)
+ break;
+
+ struct timespec ts = {1, 0};
+ nanosleep(&ts, NULL);
+ }
+
+if (msgctl(msgID, IPC_RMID, NULL))
+ {
+ int e = errno;
+ printfd(__FILE__, "StopScriptExecuter() - msgctl for IPC_STAT failed: '%s'\n", strerror(e));
+ WriteServLog("Failed to remove queue: '%s'", strerror(e));
+ }
+else
+ {
+ WriteServLog("Queue removed successfully.");
+ }
+
+KillExecuters();
+}
+//-----------------------------------------------------------------------------