#include
uid_t getuid(void);
uid_t geteuid(void);
分类: LINUX
2012-03-02 13:43:50
#include
#include
uid_t getuid(void);
uid_t geteuid(void);
#include
#include
#include
#include
#include
int main()
{
int fd;
printf("uid study: \n");
printf("Process's uid = %d, euid = %d ", getuid(), geteuid());
if( (fd = open("test.txt", O_RDWR)) == -1 ) {
printf("Open failure, errno is %d :%s \n", errno,strerror(errno));
exit(1);
} else {
printf("Open successfully!\n");
}
close(fd);
exit(0);
}
uid study:
Process's uid = 0, euid = 0 Open failure, errno is 2 :No such file or directory
linux-beyes:/home/beyes/C # touch test.txt
linux-beyes:/home/beyes/C # ./uid.exe
uid study:
Process's uid = 0, euid = 0 Open successfully!
beyes@linux-beyes:~/C> ./uid.exe
uid study:
Process's uid = 1000, euid = 1000 Open failure, errno is 13 :Permission denied
linux-beyes:/home/beyes/C # chmod 4755 uid.exe
linux-beyes:/home/beyes/C # ll uid.exe
-rwsr-xr-x 1 root root 11582 06-18 13:02 uid.exe
linux-beyes:/home/beyes/C # exit //切换到普通用户
exit
beyes@linux-beyes:~/C> ./uid.exe
uid study:
Process's uid = 1000, euid = 0 Open successfully!