Debian Codegraph @

listings/chapter-8/limit-cpu.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <sys/resource.h>
8 #include <sys/time.h>
9 #include <unistd.h>
10
11 int main ()
12 {
13 struct rlimit rl;
14
15 /* Obtain the current limits. */
16 getrlimit (RLIMIT_CPU, &rl);
17 /* Set a CPU limit of one second. */
18 rl.rlim_cur = 1;
19 setrlimit (RLIMIT_CPU, &rl);
20 /* Do busy work. */
21 while (1);
22
23 return 0;
24 }