Problem about running a command in the background

Hey there,

I am working on a CLI application using the Cobra framework to implement the users’ budget. The users will set the budget amount for different categories and when the spending amount crosses, the user will get the alert notification through email that the user has spent money out of limitation and this will be the immediate message.

But here is another functionality: the user will also set the alert time to send the alert notification at a particular time and date.

All of these things are working fine but here is a problem that I want to deal with.

When the user writes a command like app notify, the application will start running like this$ app notify
Email sent at Date: 6/2/2024, Time: 7:00 PM
Email sent at Date: 6/3/2024, Time: 7:00 PM
Email sent at Date: 6/4/2024, Time: 7:00 PM

When I stop running this using Ctrl+C the application will not send the emails because the command is not running.

Now I want a feature like docker in which the container runs even if the docker run command is not running on the CLI or if the terminal is closed but the container is running in the background.

I don’t know how to achieve this thing. I would appreciate it if you could give me an idea about it.

Thank you!

If it is a CLI-Application you should also think about computer restarts. What you probably want is the application running as a service. Automatically starting each time the computer start (the user logs on)

Depending on Linux / Windows there are various ways for a program to run as a service (Linux Daemon, Windows Service) or just run like a task on System Startup (Windows autostart and task scheduler) - depending on your users one of these will probably do what you want.