Gnu/Linux系统C编程之 -- 用户和组
2016-03-09 11:38
495 查看
用户和组
getpwnam函数的简单使用,
编译并运行,
本文出自 “固态U盘” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1749062
getpwnam函数的简单使用,
[root@python users_groups]# cat my_getpwnam.c #include <stdio.h> #include <stdlib.h> #include <pwd.h> int main(int argc, char *argv[]) { struct passwd *pwd; if (argc < 2) { printf("Usage: %s <username>\n", argv[0]); exit(1); } pwd = getpwnam(argv[1]); if (pwd == NULL) { printf("could not get %s record\n", argv[1]); exit(1); } else { printf("find [ %s ] record, the following is the info:\n", argv[1]); printf("Username: %s\n", pwd->pw_name); printf("Uid : %ld\n", (long)pwd->pw_uid); printf("Shell : %s\n", pwd->pw_shell); } return 0; }
编译并运行,
[root@python users_groups]# gcc -g -o my_getpwnam my_getpwnam.c [root@python users_groups]# ./my_getpwnam Usage: ./my_getpwnam <username> [root@python users_groups]# ./my_getpwnam root find [ root ] record, the following is the info: Username: root Uid : 0 Shell : /bin/bash [root@python users_groups]# ./my_getpwnam www could not get www record [root@python users_groups]# ./my_getpwnam lavenliu find [ lavenliu ] record, the following is the info: Username: lavenliu Uid : 500 Shell : /bin/bash [root@python users_groups]# ./my_getpwnam lavenliu [root@python users_groups]# ./my_getpwnam taoqi find [ taoqi ] record, the following is the info: Username: taoqi Uid : 517 Shell : /bin/bash
本文出自 “固态U盘” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1749062
相关文章推荐
- linux用户登陆显示:could not open session .
- Linux与JVM的内存关系分析
- Linux-centos7防火墙问题
- Linux学习笔记:1.2 权限管理命令chmod
- Linux下ssh免密码登录配置(20160309)
- SELinux and LD_PRELOAD
- CentOS 查看IP,端口 修改IP,打开端口生效
- linux分享五:日志系统
- linux分享四:cron系统
- Linux环境编程
- Linux 4.1 系列的最大版本 4.1.18 LTS发布,带来大量修改
- windows连接centos7的gnome桌面
- Hadoop从零开始--Centos操作系统的安装
- 【转】linux线程模型
- 将编写的系统调用注册为一个正式的系统调用步骤
- linux基础教程--安装Eclipse和cdt
- [Linux]oclHashcat Examples of lots of different hash types
- linux堡垒机1.0(python写的)
- Linux-常用指令
- Linux下io磁盘调度策略及配置