Esempio n. 1
0
def getrusage(who):
    ru = ffi.new("struct rusage *")
    if lib.getrusage(who, ru) == -1:
        if ffi.errno == EINVAL:
            raise ValueError("invalid who parameter")
        raise error(ffi.errno)
    return _make_struct_rusage(ru)
Esempio n. 2
0
def getrusage(who):
    ru = ffi.new("struct rusage *")
    if lib.getrusage(who, ru) == -1:
        if ffi.errno == EINVAL:
            raise ValueError("invalid who parameter")
        raise error(ffi.errno)
    return _make_struct_rusage(ru)
Esempio n. 3
0
    def prlimit(pid, resource, limits=None):
        if not (0 <= resource < lib.RLIM_NLIMITS):
            return ValueError("invalid resource specified")

        if limits is not None:
            limits = tuple(limits)
            if len(limits) != 2:
                raise ValueError("expected a tuple of 2 integers")

            # accept and round down floats, like CPython does
            limit0 = int(limits[0])
            limit1 = int(limits[1])
        else:
            limit0 = 0
            limit1 = 0

        result = ffi.new("long long[2]")

        if lib._prlimit(pid, resource, limits is not None, limit0, limit1,
                        result) == -1:
            if ffi.errno == EINVAL:
                raise ValueError("current limit exceeds maximum limit")
            else:
                raise OSError(ffi.errno, os.strerror(ffi.errno))

        return (result[0], result[1])
Esempio n. 4
0
def getrlimit(resource):
    if not (0 <= resource < lib.RLIM_NLIMITS):
        return ValueError("invalid resource specified")

    result = ffi.new("long long[2]")
    if lib.my_getrlimit(resource, result) == -1:
        raise error(ffi.errno)
    return (result[0], result[1])
Esempio n. 5
0
def getrlimit(resource):
    if not (0 <= resource < lib.RLIM_NLIMITS):
        return ValueError("invalid resource specified")

    result = ffi.new("long long[2]")
    if lib.my_getrlimit(resource, result) == -1:
        raise error(ffi.errno)
    return (result[0], result[1])