prog_limit.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 48 b94d657a9acb
parent 27 81a574d60c15
child 51 a03372ef9714
permissions -rw-r--r--
Policy Inonsistency on many files * Whenever a piece of software terminates unexpected, * catched or not, with a help screen or not, * it indicates an ERROR and the software ==> return(s) EXIT_FAILURE committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/prog_limit.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>

int set_limit (int);

int main (int argc, char **argv)
{
    int i;

    char **args;

    if (argc < 3) {
        printf ("Usage: %s <mem> <cmd> [args]...\n", argv[0]);
        printf ("Report bugs to mbroeker@largo.homelinux.org\n");
        return EXIT_FAILURE;
    }

    if ((args = calloc ((argc - 2), sizeof (char *))) == NULL) {
        perror ("calloc");
        return EXIT_FAILURE;
    }

    for (i = 2; i < argc; i++)
        args[i - 2] = argv[i];

    args[i] = NULL;

    if (set_limit (atoi (argv[1]) * 1024 * 1024) == 0)
        execvp (argv[2], args);
    else
        perror ("Limit Error");

    if (args != NULL)
        free (args);

    return EXIT_SUCCESS;
}