Skip to content

Commit 1b870eb

Browse files
authored
Update kill-all-processes-running-from-the-game-servers-root-folder.mdx
added linux script
1 parent f18f616 commit 1b870eb

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

docs/customizations/scripts/general-scripts/kill-all-processes-running-from-the-game-servers-root-folder.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,41 @@ sidebar_label: Kill all processes running from the game server's root folder
55

66
# Kill all processes running from the game server's root folder
77

8-
This Windows batch script kills all running processes located in the game server's root directory and sub directories.
8+
These batch/shell scripts kill all running processes located in the game server's root directory and sub directories. You can configure it on the after stopped event.
99

10+
* Windows
1011
```
1112
set exelocation=%ThisService_RootDirectory:\=\\%
1213
wmic path win32_process where "ExecutablePath like '%%%exelocation%%%'" call terminate
1314
```
1415

16+
* Linux
17+
```
18+
#!/bin/bash
19+
20+
# Remove any trailing slash from the directory path for consistency
21+
ThisService_RootDirectory=${ThisService_RootDirectory%/}
22+
23+
# Loop through all process IDs
24+
for pid in $(ps -eo pid --no-headers); do
25+
# Get the executable path of the process using the /proc filesystem
26+
exe=$(readlink /proc/$pid/exe)
27+
# Check if the executable path was retrieved successfully (not empty)
28+
if [ -n "$exe" ]; then
29+
# Extract the directory of the executable
30+
exe_dir=$(dirname "$exe")
31+
# Check if the executable's directory is the specified directory or a subdirectory
32+
if [[ $exe_dir == $ThisService_RootDirectory || $exe_dir == $ThisService_RootDirectory/* ]]; then
33+
# Terminate the process
34+
kill $pid
35+
fi
36+
fi
37+
done
38+
```
39+
1540
This Windows batch script kills a specific process located in the game server's root directory.
1641

1742
```
1843
set executable=%ThisService_RootDirectory%CustomExe.exe
1944
wmic path win32_process where "ExecutablePath like '%executable:\=\\%'" call terminate
20-
``
45+
``

0 commit comments

Comments
 (0)