linux下的四个简单函数介绍:getpid, getppid, getuid, getgid

来源:互联网 发布:mac已安装软件桌面 编辑:程序博客网 时间:2024/05/21 09:52

      直接看程序:

#include <stdio.h>int main(){printf("pid:%d, ppid:%d, uid:%d, gid:%d\n", getpid(), getppid(), getuid(), getgid());return 0;}
     结果为:

 [taoge@localhost learn_c]$ echo $$
2774
[taoge@localhost learn_c]$ id
uid=501(taoge) gid=502(taoge) groups=502(taoge),501(embed)
[taoge@localhost learn_c]$ ./a.out 
pid:2898, ppid:2774, uid:501, gid:502



[taoge@localhost learn_c]$ su root
Password: 
[root@localhost learn_c]# echo &&

> ^C
[root@localhost learn_c]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@localhost learn_c]# ./a.out 
pid:2922, ppid:2905, uid:0, gid:0



[root@localhost learn_c]# su taoge
[taoge@localhost learn_c]$ echo $$
2928
[taoge@localhost learn_c]$ id
uid=501(taoge) gid=502(taoge) groups=502(taoge),501(embed)
[taoge@localhost learn_c]$ ./a.out 
pid:2946, ppid:2928, uid:501, gid:502
[taoge@localhost learn_c]$ 


     ok,  无需多说。



0 0
原创粉丝点击