小编use*_*609的帖子

如何在 Linux 中检测通过 GUI 登录的用户

我想在我的程序中捕获通过 GUI 登录的用户名。我的程序从 root 登录作为守护进程运行。如果非 root 用户通过 GUI 登录,则应通知我的程序。我正在粘贴我当前的程序,它调用一个 perl 脚本,利用系统调用来检查谁是当前登录的用户。我也在粘贴我的 perl 脚本以供参考。

#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/Xfuncs.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
int main()
{
    char *user;
    char buf[1024];
    int fd, ret;
    fd = open("/tmp/log", O_TRUNC|O_RDWR|O_CREAT);
    if (!fd) {
        printf("Error opening file\n");
        exit(1);
    }
    chmod("/tmp/log", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP
            | S_IROTH | S_IWOTH | S_IXOTH);
    daemon(0, 0);
    while (1) {
        system("perl /home/curr-usr.pl");
        sleep(5);
    } 
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

用于获取当前用户登录的 perl 脚本。

#!/usr/bin/perl
my …
Run Code Online (Sandbox Code Playgroud)

c linux gnome xlib

2
推荐指数
1
解决办法
4367
查看次数

如何在Linux中获得正确的时间

目前我能够在诸如此类localtime() gettimeofday()等功能的帮助下获得当前日期时间time.h

假设用户修改Linux中的日期和时间设置以将日期更改为某个先前的日期,当我调用上述函数时,我将获得这些更改.

无论用户是否更改系统日期和时间设置,我仍然希望获得当前时间,即说出今天的时间.

有什么办法可以达到同样的目的吗?

c linux time datetime

0
推荐指数
1
解决办法
1890
查看次数

标签 统计

c ×2

linux ×2

datetime ×1

gnome ×1

time ×1

xlib ×1