gpt4 book ai didi

posix - 我如何确定是否是 POSIX 应用程序。在系统启动后 5 分钟内运行?

转载 作者:行者123 更新时间:2023-12-04 01:40:50 28 4
gpt4 key购买 nike

来自 C++ 应用程序。为 AIX、HP-UX、Linux、OSX 和 Solaris 编译是否有一种简单的方法来确定应用程序是否可用。在系统启动后 5 分钟内运行?

在 Windows 上我可以这样做:

// return true if OS has recently booted up
bool at_os_boot_time()
{
/* GetTickCount() returns the number of miliseconds since system start.
So "...the time will wrap around to zero if the system is run
continuously for 49.7 days" - so this function will erroneously
return true for a 5 minute period 49.7 days after boot */
return ::GetTickCount() < 5 * 60 * 1000;
}

我找不到 Unix 世界中的等价物。

最佳答案

这是来自 linux 上的 kernel.h:

struct sysinfo;
extern int do_sysinfo(struct sysinfo *info);

#endif /* __KERNEL__ */

#define SI_LOAD_SHIFT 16
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 short pad; /* explicit padding for m68k */
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: libc5 uses this.. */
};

关于posix - 我如何确定是否是 POSIX 应用程序。在系统启动后 5 分钟内运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1372309/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com