我必须创建一个程序,显示“正常运行时间”的结果。如何在Linux中用C++获取登录用户数?
最佳答案
好吧,如果您只想使用 C++ 执行命令,您可以使用:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//execute uptime command
system("uptime");
//one way to "count" the currently logged users
system("users | wc -w");
//or another way
system("who | wc -l");
return 0;
}
关于c++ - 在Linux中用C++检索登录用户的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30490326/