File: sys.c

package info (click to toggle)
python-psutil 7.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,312 kB
  • sloc: python: 19,411; ansic: 15,378; makefile: 465; javascript: 153; sh: 54
file content (31 lines) | stat: -rw-r--r-- 890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <Python.h>
#include <sys/sysctl.h>
#include <stdio.h>
#include <sys/param.h>  // OS version
#if defined(PSUTIL_FREEBSD) || defined(PSUTIL_NETBSD)
    #include <utmpx.h>
#elif defined(PSUTIL_OPENBSD)
    #include <utmp.h>
#endif

#include "../../arch/all/init.h"


// Return a Python float indicating the system boot time expressed in
// seconds since the epoch.
PyObject *
psutil_boot_time(PyObject *self, PyObject *args) {
    // fetch sysctl "kern.boottime"
    static int request[2] = { CTL_KERN, KERN_BOOTTIME };
    struct timeval boottime;

    if (psutil_sysctl(request, 2, &boottime, sizeof(boottime)) != 0)
        return NULL;
    return Py_BuildValue("d", (double)boottime.tv_sec);
}