linux - RUID & EUID after exec() -


with fork() operation child process inherits attribute real , effective user id's parent process, how behaves when exec() performed ?

exec not change of them. linux manual :

the exec() family of functions replaces current process image new process image.

the exec changes process image (the code , data segment in memory), not change process descriptor of new process created fork. process descriptor contains real , effective id, because not changed exec call, effective , real id not changed neither.

i hope have been clear explaining concept.

the real , effective uid , gid of child process equal real , effective uid , gid of parent process. therefore, when child process calls exec values not modified.

in order prove wrote small application creates child process calls exec. exec system call runs application prints out value of gid , uid of current process. in addition gid , uid of parent process showen well, can compare them.

main.c

#include <stdio.h>  #include <unistd.h>    void print_info () {    printf("     uid           gid  \n"         "real      %d  real      %d  \n"         "effective %d  effective %d  \n",              getuid (),     getgid (),              geteuid(),     getegid()     );  return;  }   int main () {   pid_t pid;   int status;   pid = fork();    if (!pid) {    puts("childe process\n");     execv("./uid.out", null);     return;  }    wait(status);    printf("father %d -------------------\n", getpid());  print_info();  puts("--------------------------------");    return 0;  }  

uid.c

#include <stdio.h>  #include <unistd.h>   int main () {    printf("child  %d -------------------\n", getpid());    printf("     uid           gid  \n"         "real      %d  real      %d  \n"         "effective %d  effective %d  \n",              getuid (),     getgid (),              geteuid(),     getegid()     );   puts("---------------------------------");  return 0;  } 

output :

child  17436 -------------------      uid           gid   real      1000  real      1000   effective 1000  effective 1000   --------------------------------- father 17435 -------------------      uid           gid   real      1000  real      1000   effective 1000  effective 1000   -------------------------------- 

let me know if need more info.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -