#include <utmp.h>
struct utmp *pututline(struct utmp *ut);
#include <utmpx.h>
struct utmpx *pututxline(const struct utmpx *);
#include <stdio.h>
#include <string.h>
#include <utmp.h>
#include <utmpx.h>
int main()
{
struct utmpx ut;
bzero(&ut, sizeof(struct utmpx));
ut.ut_type = USER_PROCESS; //普通用户进程
ut.ut_pid = getpid(); //本进程PID
strncpy(ut.ut_user, "beyes", 5);
strncpy(ut.ut_line, "pts/4", 5);
strncpy(ut.ut_id, "/4", 2);
strncpy(ut.ut_host, "groad.net", strlen("groad.net"));
time((time_t *)&ut.ut_tv.tv_sec); /* 标记时间 */
setutxent();
pututxline(&ut);
sleep(60); /* 悬停 1 分钟来观察*/
endutxent();
return 0;
}
su -c ./pututxline
Password: //这里输入 root 密码
beyes@linux-xh53:~/shell/moko> who
beyes :0 2012-01-02 09:07 (console)
beyes pts/0 2012-01-02 09:07
beyes pts/4 2012-01-02 17:17 (groad.net)
beyes pts/2 2012-01-02 11:27 (192.168.1.100)
utmpx 结构 |
beyes@linux-xh53:~/shell/moko> last |more
beyes pts/4 groad.net Mon Jan 2 17:10 gone - no logout
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |