setid.c 615 B

123456789101112131415161718192021222324252627
  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. {
  10. if( setpgid( getpid(), 0 ) == -1 ) {
  11. perror( "setpgid" );
  12. }
  13. printf( "%d belongs to process group %d\n",
  14. getpid(), getpgrp() );
  15. if( setregid(-1, -1) == -1 ) {
  16. perror( "setregid" );
  17. }
  18. printf("%d has egid %d and gid %d\n", getpid(), getegid(), getgid());
  19. if( setreuid(-1, -1) == -1 ) {
  20. perror( "setreuid" );
  21. }
  22. printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid());
  23. return 0;
  24. }