I have console app that would start as console and as Linux daemon.

How can I determine that app started as Linux daemon (not console)?

migrated from stackoverflow.com Sep 17 '18 at 19:48

This question came from our site for professional and enthusiast programmers.


I'd recommend passing an extra command line parameter when you start as Linux daemon and checking for the existence of that extra command line parameter in your code.

  • yes, I thought about this version. But I wanted to know if there is a standard functional for this. – Viktor Sep 17 '18 at 13:34
  • You could use Process.Start() to run "ps -eo 'tty,pid,comm' | grep ^?" to find all daemon processes on Linux (see unix.stackexchange.com/questions/175380/…) and then see if your currently running process is in this list. – K Johnson Sep 17 '18 at 21:25

Your Answer

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