I'd like to start a specific process for specific user when he opens his first session and terminate the process when user closes his last session. No mater how many user sessions are active, there have to be only one process instance active and it have to be terminated when there are no more sessions. How can I achieve it?

supplement: The process has setuid attribute set and is spawned with root privileges.

  • tty or desktop, maybe ssh as well. cron: never. – ardabro Aug 4 '17 at 19:34

This all depends on what system you are using. As far as starting a process, I would add it to your shell's rc file if you want it to start when a shell is opened. You could add it to your .bashrc or .zshrc or the like. As far as terminating it goes, depending on the process it will be terminated upon logout. You can also use a service with systemd or equivalent that runs on startup and is not dependent on your shells rc. What system are you using and what is the process?

|improve this answer|||||
  • Linux, Debian. .bashrc obviously doesn't make a trick. It would start new process with every terminal. I want to have ONE and only ONE process per user. The seid process is an instant mirroring but it doesn't mater so much. – ardabro Aug 4 '17 at 19:33
  • look into /etc/init.d or systemd to accomplish this. I will update my answer here in a min with an example. – archae0pteryx Aug 4 '17 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.