misc.c 585 Bytes
/*
 * Misc pli  routines
 */
 
#include <stdio.h>
#include <signal.h>
#include <sys/resource.h>

#include "acc_user.h"

static void
exceededtimelimit(int sig)
{
    fprintf(stderr, "ERROR: Exceeded time limit.  $finish()\n");
    tf_dofinish();
}



void
set_timelimit(int data, int reason)
{
    int seconds;
    struct rlimit rlim;
    
    seconds = tf_getp(1);
    fprintf(stderr, "setting time limit to %d:%02d\n", seconds/60, seconds%60);
    rlim.rlim_cur = rlim.rlim_max = seconds;
    
    sigset(SIGXCPU, exceededtimelimit);
    
    setrlimit(RLIMIT_CPU, &rlim);
        
}