|
@@ -1,4 +1,38 @@
|
|
|
|
|
|
|
|
|
|
+ -- 使用os_execute执行系统命令获取PID
|
|
|
|
|
+local function get_pid()
|
|
|
|
|
+ local handle = io.popen("ps aux | grep ./logic | grep -v grep | awk '{print $2}'", "r")
|
|
|
|
|
+ local pid = handle:read("*a")
|
|
|
|
|
+ handle:close()
|
|
|
|
|
+ return tonumber(pid)
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+-- 在Windows上获取PID的另一种方法
|
|
|
|
|
+local function get_pid_windows()
|
|
|
|
|
+ local handle = io.popen("echo %PROCESS_ID%", "r")
|
|
|
|
|
+ local pid = handle:read("*a")
|
|
|
|
|
+ handle:close()
|
|
|
|
|
+ return tonumber(pid)
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+-- 根据操作系统选择正确的函数
|
|
|
|
|
+local get_pid_func
|
|
|
|
|
+if jit.os == "Windows" then
|
|
|
|
|
+ get_pid_func = get_pid_windows
|
|
|
|
|
+else
|
|
|
|
|
+ get_pid_func = get_pid
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+local function createPidFile ()
|
|
|
|
|
+ local pid = get_pid_func()
|
|
|
|
|
+ local f,err = io.open("logicPidFile","w")
|
|
|
|
|
+ if not f then
|
|
|
|
|
+ print("open file failed",err)
|
|
|
|
|
+ return
|
|
|
|
|
+ end
|
|
|
|
|
+ f:write(pid)
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
if jit then
|
|
if jit then
|
|
|
jit.off()
|
|
jit.off()
|
|
|
jit.flush()
|
|
jit.flush()
|