File: limit.lua

package info (click to toggle)
lua-posix 36.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,720 kB
  • sloc: ansic: 5,462; makefile: 21; sh: 6
file content (25 lines) | stat: -rw-r--r-- 529 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
#! /usr/bin/env lua

-- limit.lua
-- Limiting the CPU time used by a child process;
-- it will be killed and we don't get the final message

local M = require 'posix.sys.resource'


local times = require 'posix.sys.times'.times

M.setrlimit (M.RLIMIT_CPU, {rlim_cur=1, rlim_max=1})

local t = times().elapsed

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