Какой API я называю для получения системного времени работы?

В случае стекового потока они используют ASP.NET MVC, а не веб-формы ASP.NET. В веб-формах URL-адрес указывает на файл на вашем диске, а MVC указывает на действие контроллера. Если вы используете веб-формы, вы хотите использовать переписывание URL. У Скотта Гатри есть хорошая статья о переписывании URL.

28
задан Stéphane 8 October 2009 в 21:31
поделиться

3 ответа

The system call you're looking for is sysinfo().

It's defined in sys/sysinfo.h

Its signature is: int sysinfo(struct sysinfo *info)

Since kernel 2.4, the structure has looked like this:

struct sysinfo {
    long uptime;             /* Seconds since boot */
    unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
    unsigned long totalram;  /* Total usable main memory size */
    unsigned long freeram;   /* Available memory size */
    unsigned long sharedram; /* Amount of shared memory */
    unsigned long bufferram; /* Memory used by buffers */
    unsigned long totalswap; /* Total swap space size */
    unsigned long freeswap;  /* swap space still available */
    unsigned short procs;    /* Number of current processes */
    unsigned long totalhigh; /* Total high memory size */
    unsigned long freehigh;  /* Available high memory size */
    unsigned int mem_unit;   /* Memory unit size in bytes */
    char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
};

Have fun!

37
ответ дан 28 November 2019 в 02:44
поделиться

Прочтите файл / proc / uptime и возьмите первое десятичное число в качестве времени безотказной работы в секундах.

Из man 5 proc :

   /proc/uptime
          This file contains two numbers: the uptime of the  system  (sec‐
          onds), and the amount of time spent in idle process (seconds).
14
ответ дан 28 November 2019 в 02:44
поделиться

Это будет примерно так.

#include <stdio.h>
#include <errno.h>
#include <linux/unistd.h>       /* for _syscallX macros/related stuff */
#include <linux/kernel.h>       /* for struct sysinfo */
#include <sys/sysinfo.h>

long get_uptime()
{
    struct sysinfo s_info;
    int error = sysinfo(&s_info);
    if(error != 0)
    {
        printf("code error = %d\n", error);
    }
    return s_info.uptime;
}

См. "Man sysinfo" для получения дополнительной информации.

17
ответ дан 28 November 2019 в 02:44
поделиться
Другие вопросы по тегам:

Похожие вопросы: