2
0

setid.c 609 B

1234567891011121314151617181920212223242526
  1. /*
  2. * The process joins process group 0.
  3. */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. int main(void) {
  9. if( setpgid( getpid(), 0 ) == -1 ) {
  10. perror( "setpgid" );
  11. }
  12. printf( "%d belongs to process group %d\n",
  13. getpid(), getpgrp() );
  14. if( setregid(-1, -1) == -1 ) {
  15. perror( "setregid" );
  16. }
  17. printf("%d has egid %d and gid %d\n", getpid(), getegid(), getgid());
  18. if( setreuid(-1, -1) == -1 ) {
  19. perror( "setreuid" );
  20. }
  21. printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid());
  22. return 0;
  23. }