tst-fork4.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Test of fork updating child universe's pthread structures.
  2. Copyright (C) 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <sys/wait.h>
  21. #include <string.h>
  22. static int
  23. do_test (void)
  24. {
  25. pthread_t me = pthread_self ();
  26. pid_t pid = fork ();
  27. if (pid < 0)
  28. {
  29. printf ("fork: %m\n");
  30. return 1;
  31. }
  32. if (pid == 0)
  33. {
  34. int err = pthread_kill (me, SIGTERM);
  35. printf ("pthread_kill returned: %s\n", strerror (err));
  36. return 3;
  37. }
  38. int status;
  39. errno = 0;
  40. if (wait (&status) != pid)
  41. printf ("wait failed: %m\n");
  42. else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGTERM)
  43. {
  44. printf ("child correctly died with SIGTERM\n");
  45. return 0;
  46. }
  47. else
  48. printf ("child died with bad status %#x\n", status);
  49. return 1;
  50. }
  51. #define TEST_FUNCTION do_test ()
  52. #include "../test-skeleton.c"