File: limit.lua

package info (click to toggle)
lua-posix 31-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,604 kB
  • ctags: 1,346
  • sloc: sh: 14,309; ansic: 4,794; perl: 76; makefile: 41
file content (20 lines) | stat: -rw-r--r-- 396 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- limit.lua
-- Limiting the CPU time used by a child process;
-- it will be killed and we don't get the final message

local posix = require 'posix'

posix.setrlimit ('cpu',1,1)

local t = posix.times 'elapsed'

local pid = posix.fork ()
if pid == 0 then -- child
  print 'start'
  for i = 1, 1e9 do
  end
  print 'finish'
else
  print (posix.wait (pid))
  print (posix.times 'elapsed' - t)
end