Ejemplo n.º 1
0
def get_memory_size(unit_format='m'):
    '''获取内存大小
    '''
    size = utils.read_one_line("/proc/meminfo").split()[1]
    size = "%s%s" % (size, "k")
    size = utils.custom_format(size, base=1024, unit_format=unit_format)
    return size
Ejemplo n.º 2
0
def sysctl_kernel(key, value=None):
    """(Very) partial implementation of sysctl, for kernel params"""
    if value is not None:
        # write
        utils.write_one_line('/proc/sys/kernel/%s' % key, str(value))
    else:
        # read
        out = utils.read_one_line('/proc/sys/kernel/%s' % key)
        return int(re.search(r'\d+', out).group(0))
Ejemplo n.º 3
0
def sysctl(key, value=None):
    """Generic implementation of sysctl, to read and write.

    :param key: A location under /proc/sys
    :param value: If not None, a value to write into the sysctl.

    :return: The single-line sysctl value as a string.
    """
    path = '/proc/sys/%s' % key
    if value is not None:
        utils.write_one_line(path, str(value))
    return utils.read_one_line(path)