File: pid.lua

package info (click to toggle)
eja 9.5.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 1,340 kB
  • ctags: 3,142
  • sloc: ansic: 15,010; makefile: 255
file content (50 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- Copyright (C) 2007-2014 by Ubaldo Porcheddu <ubaldo@eja.it>


function ejaPidWrite(name,pid)
 if not pid then
  pid=ejaPid()
 end
 ejaFileWrite(eja.pathLock..'eja.pid.'..name,pid)
end


function ejaPidKill(name) 
 local pid=ejaFileRead(eja.pathLock..'eja.pid.'..name)
 if pid and tonumber(pid) > 0 then 
  if ejaKill(pid,9) == 0 then
   ejaFileRemove(eja.pathLock..'eja.pid.'..name)
   ejaTrace('[kill] %d %s',pid,name)
  end
 end
end


function ejaPidKillTree(name) 
 local pid=ejaFileRead(eja.pathLock..'eja.pid.'..name)
 if pid and tonumber(pid) > 0 then 
  local pidTable=ejaProcPidChildren(pid)
  if ejaKill(pid,9) == 0 then
   for k,v in next,pidTable do 
    ejaTrace('[ejaPidKillTree] kill %d',v)
    ejaKill(v,9) 
   end
   ejaFileRemove(eja.pathLock..'eja.pid.'..name)
   ejaTrace('[ejaPidKillTree] %d %s',pid,name)
  end
 end
end


function ejaPidKillTreeSub(name) 
 local pid=ejaFileRead(eja.pathLock..'eja.pid.'..name)
 if pid and tonumber(pid) > 0 then 
  local pidTable=ejaProcPidChildren(pid)
  for k,v in next,pidTable do 
   ejaTrace('[ejaPidKillTreeSub] kill %d',v)
   ejaKill(v,9) 
  end
 end
end