All Projects β†’ jirihnidek β†’ Daemon

jirihnidek / Daemon

Licence: gpl-2.0
Simple example of daemon for Linux

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Daemon

discord-giveaways-bot
🎁Giveways Bot using the discord-giveaways package
Stars: ✭ 118 (-55.81%)
Mutual labels:  example
movies
Real world isomorphic application for movies search, based on Webpack 5 / Express / React 17 + Redux-Saga / Bootstrap 4.6 + CSS Modules / i18next / SSR
Stars: ✭ 20 (-92.51%)
Mutual labels:  example
Rpcx Examples
examples for the latest rpcx
Stars: ✭ 256 (-4.12%)
Mutual labels:  example
golang-cognito-example
Golang example of using AWS Cognito APIs (Register, Login, Verify Phone, Refresh token)
Stars: ✭ 74 (-72.28%)
Mutual labels:  example
instantsearch-android-examples
Example apps built with algolia/instantsearch-android
Stars: ✭ 60 (-77.53%)
Mutual labels:  example
mean-stack-angular-8-blog-cms
MEAN Stack (Angular 8) Tutorial: Build a Simple Blog CMS Example
Stars: ✭ 19 (-92.88%)
Mutual labels:  example
Object-Detection-Using-YOLO-v2-Deep-Learning
MATLAB example of deep learning based object detection using Yolo v2 with ResNet50 Base Network
Stars: ✭ 34 (-87.27%)
Mutual labels:  example
Flutter Ui Nice
More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.
Stars: ✭ 3,092 (+1058.05%)
Mutual labels:  example
Tensorflow-lite-kotlin-samples
πŸ“ŒThis repo contains the kotlin implementation of TensorflowLite Example Android AppsπŸš€
Stars: ✭ 17 (-93.63%)
Mutual labels:  example
Examples Win32
Shows how to use Win32 controls by programming code (c++17).
Stars: ✭ 22 (-91.76%)
Mutual labels:  example
serverless-lighthouse-template
Run lighthouse audits from headless chrome in lambda.
Stars: ✭ 25 (-90.64%)
Mutual labels:  example
modern-linux.info
Learning Modern Linux book website
Stars: ✭ 35 (-86.89%)
Mutual labels:  systemd
clean architecture
Clean Architecture Simple App.
Stars: ✭ 16 (-94.01%)
Mutual labels:  example
mooseware
πŸ’€ Skeleton for writing a middleware handler
Stars: ✭ 47 (-82.4%)
Mutual labels:  example
Create React App Typescript Todo Example 2020
πŸš€ Create React App TypeScript Todo Example 2020
Stars: ✭ 255 (-4.49%)
Mutual labels:  example
EnttPong
Built for EnTT, at the request of the developer as a demo.
Stars: ✭ 51 (-80.9%)
Mutual labels:  example
reddit-clone
Reddit Clone using Laravel 5.4 / Clon de Reddit usando Laravel 5.4
Stars: ✭ 22 (-91.76%)
Mutual labels:  example
Project Minimek
A sample app to demonstrate various useful Redux techniques, accompanying the blog series at http://blog.isquaredsoftware.com/series/practical-redux
Stars: ✭ 266 (-0.37%)
Mutual labels:  example
Vaporschool
Learn how to build vapor applications from rookie to champion in a constructive way!
Stars: ✭ 259 (-3%)
Mutual labels:  example
cobra-example
minimal example of cobra app
Stars: ✭ 43 (-83.9%)
Mutual labels:  example

Example of Linux Daemon

This repository contains simple example of daemon for Linux OS. This repository also contains examples of starting scripts.

When you want to create super simple daemon, then it is very easy. You can write something like this in C and call it daemon.c:

/* Compile this with gcc -o daemon daemon.c */

#include <unistd.h>

int main(void)
{
    while(1) {
        /* TODO: do something usefull here ;-) */
        sleep(1);
    }
}

and write some super simple systemd service file called simple-daemon.service:

[Unit]
Description=Super simple daemon

[Service]
Type=simple
ExecStart=/usr/bin/daemon

[Install]
WantedBy=multi-user.target

and then you can run it as UNIX daemon, but such daemon do not have some nice features like reloadin configure files, loging, etc. This repository and sources can help you to understand how UNIX daemons works.

Requirements

To build example of the daemon you have to have following tools

  • CMake
  • GCC/CLang

Build

To build example of daemon you have to type following commands:

git clone https://github.com/jirihnidek/daemon.git
cd daemon
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ../
make
sudo make install

Usage

You can test running daemon from command line:

./bin/daemon

But running the app in this way is not running running daemon. Let have a look at command line parameters and arguments

Usage: ./bin/daemon [OPTIONS]

 Options:
  -h --help                 Print this help
  -c --conf_file filename   Read configuration from the file
  -t --test_conf filename   Test configuration file
  -l --log_file  filename   Write logs to the file
  -d --daemon               Daemonize this application
  -p --pid_file  filename   PID file used by daemonized app

When you will run ./bin/daemon with parameter --daemon or -d, then it will become real UNIX daemon. But this is not the way, how UNIX daemons are started nowdays. Some init scripts or service files are used for this purpose.

When you use Linux distribution using systemd, then you can try start daemon using

systemctl start simple-daemon
systemctl status simple-daemon
systemctl reload simple-daemon
systemctl stop simple-daemon

Note: The unit files simple-daemon.service and forking-daemon.service are copied to the directory /usr/lib/systemd/system during installation using make install command.

When you use RedHat 4/5/6 or CentOS, then you can try to use init script:

cp daemon.init /etc/rc.d/init.d/daemond

Then it should be possible to control daemon using:

service daemon start
service daemon status
service daemon reload
service daemon stop
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].