1

For the past week, I been having a bug that my python code hasn't been doing a cleanup process properly. It was suppose to once it captures a signal caused by closing the terminal, it does some cleanup actions but in the end, it never did that.

Just a few moments ago I figured out why, since my python code required root privileges (A few commands it calls requires such privileges) to run, and because of my terminal was a user terminal, my signal was block and never went through.

So preferably using some sort of bash script or something, how do I escalate a signal so that my python code can capture it. On my debian system, calling sudo for anything doesn't cause a password prompt.

closed as unclear what you're asking by Kaz, Stephen Rauch, xhienne, Rui F Ribeiro, cas Aug 5 '17 at 11:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You probably want to check that os.getuid() returns zero somewhere near the beginning of your code. – glenn jackman Oct 15 '15 at 0:57
  • root privilege will not stop a the TTY code in the kernel from sending a signal to a process in the TTY's session, like a SIGHUP. – Kaz Aug 5 '17 at 5:18
  • Try sudo cat to run cat as root (effective UID 0). You will see that you can kill it with Ctrl-C. That works by your TTY sending a SIGINT signal to this process. – Kaz Aug 5 '17 at 5:22
  • Apparently, you are asking how a non-privileged process can send a signal to a privileged one. Since the latter is a Python program you wrote and started, why not use the same way you made your code running in privileged mode? You don't tell us enough on how things work (how did you start your Python code? sudo? su? SUID bit?) – xhienne Aug 5 '17 at 8:50