Advertisement
Jakowlew

kill xorg v2

Mar 25th, 2024
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. bool Session::stopX()
  2.     {
  3.         spdlog::info("stopx");
  4.  
  5.         if (!m_X) {
  6.             spdlog::info("Xorg app is nullptr");
  7.             return false;  
  8.         }
  9.  
  10.         const auto pgidOpt = m_X->pgid();
  11.         if (!pgidOpt) {
  12.             spdlog::info("failed to get pgid for Xorg, some processes may persist after kill");
  13.             return m_X->kill();
  14.         }
  15.         const auto pgid = *pgidOpt; // pgid of app process
  16.  
  17.         spdlog::info("search for xinit and xorg");
  18.  
  19.         for (const auto xinit: pids_by_name("xinit")
  20.             | views::filter(_1->*&Pids::pgid == pgid)
  21.         ) {
  22.             spdlog::info("found xinit pid={} pgid={}", xinit.pid, xinit.pgid);
  23.             for (const auto xorg : pids_by_name("Xorg")
  24.                 | views::filter(_1->*&Pids::ppid == xinit.pid)
  25.             ) {
  26.                 spdlog::info("found Xorg pid={} pgid={}", xorg.pid, xorg.pgid);
  27.                 if (kill(-xorg.pgid, SIGKILL) == -1) {
  28.                     spdlog::warn("failed to kill Xorg");
  29.                 }
  30.             }
  31.         }
  32.  
  33.         return m_X->kill();
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement