test_klp-call_getpid.c 670 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2023 SUSE
  4. * Authors: Libor Pechacek <lpechacek@suse.cz>
  5. * Marcos Paulo de Souza <mpdesouza@suse.com>
  6. */
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <sys/syscall.h>
  10. #include <sys/types.h>
  11. #include <signal.h>
  12. static int stop;
  13. static int sig_int;
  14. void hup_handler(int signum)
  15. {
  16. stop = 1;
  17. }
  18. void int_handler(int signum)
  19. {
  20. stop = 1;
  21. sig_int = 1;
  22. }
  23. int main(int argc, char *argv[])
  24. {
  25. long count = 0;
  26. signal(SIGHUP, &hup_handler);
  27. signal(SIGINT, &int_handler);
  28. while (!stop) {
  29. (void)syscall(SYS_getpid);
  30. count++;
  31. }
  32. if (sig_int)
  33. printf("%ld iterations done\n", count);
  34. return 0;
  35. }