Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8KB

  1. /*
  2. * Carla process utils
  3. * Copyright (C) 2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_PROCESS_UTILS_HPP_INCLUDED
  18. #define CARLA_PROCESS_UTILS_HPP_INCLUDED
  19. #include "CarlaUtils.hpp"
  20. #ifdef CARLA_OS_LINUX
  21. # include <signal.h>
  22. # include <sys/prctl.h>
  23. #endif
  24. // --------------------------------------------------------------------------------------------------------------------
  25. // process functions
  26. /*
  27. * Set current process name.
  28. */
  29. static inline
  30. void carla_setProcessName(const char* const name) noexcept
  31. {
  32. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  33. #ifdef CARLA_OS_LINUX
  34. ::prctl(PR_SET_NAME, name, 0, 0, 0);
  35. #endif
  36. }
  37. /*
  38. * Set flag to automatically terminate ourselves if parent process dies.
  39. */
  40. static inline
  41. void carla_terminateProcessOnParentExit(const bool kill) noexcept
  42. {
  43. #ifdef CARLA_OS_LINUX
  44. //
  45. ::prctl(PR_SET_PDEATHSIG, kill ? SIGKILL : SIGTERM);
  46. // TODO, osx version too, see https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits
  47. #endif
  48. // maybe unused
  49. return; (void)kill;
  50. }
  51. // --------------------------------------------------------------------------------------------------------------------
  52. #endif // CARLA_PROCESS_UTILS_HPP_INCLUDED