*nix 获取登录者

函数:

1 #include<unistd.h>
2
3 char * getlogin(void);

测试函数:

1 #include<stdio.h>
2 #include<unistd.h>
3
4 int main(void){
5 char * username;
6 username=getlogin();
7 printf("the login is %s\n",username);
8 return 0;
9 }

make:

1 make:
2 cc -g fig8_15.c -o fig8_15
3 clean:
4 rm -rf fig8_15

 获取该程序或进程所在用户的用户名,但在守护进程中是不能够获取的。

原文地址:https://www.cnblogs.com/changefuture/p/2306338.html