0

I am writing for generic linux/unix systems and have an unusual use case for which the design of the program is not clear to me.

(FYI: for those not familiar with the unix mentality, sometimes called the Unix Philosophy, the idea is to provide functionality by making lots of small programs that run independently, rather than making large conglomerate applications.)

So, in my case I want an application that will provide alerts. The application would be run from the command line with parameters defining the characteristics of the alert, then it would put itself into the background and wake up when the alert needs to be issued.

The problem is when a second alert is created. Rather than create a second process, I would like the application to notify the existing background process of the new alert and add it to its list of alerts. That way I have only a single "alert" process at any given time. One advantage of this is that since only one process controls all the alerts, it can list them. For example, the user might give a command like "alert list" and alert(2) will notify the existing alert process of the request and exit, then the existing process will print out all the alerts that are pending, then go into the background again.

What is the right way to do this?

Tyler Durden
  • 11,156
  • 9
  • 64
  • 126
  • Have you looked at the linux program `watch` ? I think it does all of this "out-of-the-box". And sorry, but StackOverflow is dedicated to helping solve programming code problems. It may be more appropriate for [softwarerecs.se], but read their help concerning on-topic questions. You might want to reread [Help On-topic](https://stackoverflow.com/Help/On-topic) and [Help How-to-ask](https://stackoverflow.com/Help/How-to-ask) before posting more Qs here. Good luck. – shellter Dec 31 '20 at 23:40
  • @shelter this is coding problem, i am not asking about existing applications, I am writing the application; I specifically am writing in C, I updated the question (i thought that was obvious because most unix system programs are written in C) – Tyler Durden Jan 01 '21 at 01:10
  • A simple approach would be to have the daemon re-read a config file upon receipt of a SIGHUP. To add an alert, edit the config file and send the signal – William Pursell Jan 01 '21 at 03:44
  • @WilliamPursell I was hoping that there was some kind of unixy standard approach to this problem, I know there are various ways to roll my own, but I don't want to do something weird and find out later that particular method is standard. For example, I know I can do this by just having the second process open a pipe to the first and send the parameters to the master process via the pipe, but once again if their is a standard way to do it, then I would prefer that to start hacking pipes. – Tyler Durden Jan 01 '21 at 13:17
  • IMO, the standard way is to send a SIGHUP to tell the daemon to re-read a config file. There are certainly issues with that approach, but a lot of daemons do that. (eg syslogd, sshd, ...) – William Pursell Jan 01 '21 at 13:24
  • https://venam.nixers.net/blog/unix/2017/06/04/daemons.html – William Pursell Jan 01 '21 at 13:25
  • @WilliamPursell Well, there is no reason to be creating a file to share the information. A pipe is a simpler approach and does not require disk activity or changes to the file system. – Tyler Durden Jan 01 '21 at 13:35

0 Answers0