Uptime under linux in C

后端 未结 3 1741
说谎
说谎 2021-02-20 05:41

How can I retrieve uptime under linux using C? (without using popen and/or /proc)

Thanks

3条回答
  •  无人共我
    2021-02-20 06:03

    Via top or via uptime, but I don't know about any syscall, someone will for sure :)

    uptime should be rather easy to parse.

    Just stumbled into this:

    #include 
    
    struct sysinfo info;
    sysinfo(&info);
    printf("Uptime = %ld\n", info.uptime);
    

提交回复
热议问题