1.建立文件1.txt,屬於root用戶,root組,權限爲700
2.建立程序文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>ide
#define BUFFSIZE 10ui
int main()
{
int fd;
char buf[BUFFSIZE];
fd = open("1.txt", O_RDWR);
if(fd < 0)
{
perror("1.txt");
return 1;
}
if(read(fd, buf, 10) < 0)
{
perror("1.txt");
return 1;
}
//打印進程uid,有效uid
printf("%d %d %s\n", getuid(), geteuid(), buf);
exit(1);
}
編譯成a.out二進制文件
3.二進制文件a.out權限修改成4770,用戶屬於root,組爲當前用戶所在組,執行./a.out能夠執行成功,由於進程有效用戶已經爲root進程