Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:14:45+00:00 2026-06-11T22:14:45+00:00

I read about Daemon Programming and i think I’ll be needing this to detect

  • 0

I read about Daemon Programming and i think I’ll be needing this to detect my devices if online or not eg(RS232, usb, ethernet). then fetch in a webservice PHP.

The code from this site. http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html

I added some parts to test if i can detect devices.

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
int devfd;
int main(int argc, char *argv[]) {

        int c;


        while((c=getopt(argc,argv,"s")) != -1)
            switch(c){

            case 's': devfd = open("/dev/ttyUSB0", O_RDWR);
                        if(devfd==-1){
                        printf("offline\n");
                        }
                        else{
                        printf("online\n");
                        }
                        break;
            default: printf("Wrong command\n");

            }

        /* Our process ID and Session ID */
        pid_t pid, sid;

        /* Fork off the parent process */
        pid = fork();
        if (pid < 0) {
                exit(EXIT_FAILURE);
        }
        /* If we got a good PID, then
           we can exit the parent process. */
        if (pid > 0) {
                exit(EXIT_SUCCESS);
        }

        /* Change the file mode mask */
        umask(0);

        /* Open any logs here */        

        /* Create a new SID for the child process */
        sid = setsid();
        if (sid < 0) {
                /* Log the failure */
                exit(EXIT_FAILURE);
        }



        /* Change the current working directory */
        if ((chdir("/")) < 0) {
                /* Log the failure */
                exit(EXIT_FAILURE);
        }



        /* Daemon-specific initialization goes here */

        /* The Big Loop */
        while (1) {



        }
   exit(EXIT_SUCCESS);
}

I added this code..

while((c=getopt(argc,argv,"s")) != -1)
            switch(c){

            case 's': devfd = open("/dev/ttyUSB0", O_RDWR);
                        if(devfd==-1){
                        printf("offline\n");
                        }
                        else{
                        printf("online\n");
                        }
                        break;
            default: printf("Wrong command\n");

            }

so doing it like this in the terminal.

./daemon -s //prints offline because the device USB0 is not connected.

Is there another way for me to detect my devices?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:14:47+00:00Added an answer on June 11, 2026 at 10:14 pm

    If it has udev, you can use libudev to detect and monitor your devices. Checkout nice tutorial from signal11.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Read about the issue in this stackoverflow question . Still have the same issue
I read about this question on referencing one project into another and this question
Read this question today about safe and unsafe code I then read about it
I read about Endianness and understood squat... so I wrote this main() { int
I read about the requirements of NDK programming on Windows which said we require
I read about the popup menu in the documentation here . I'm not clear
I read about JSON from internet but still i have not got the grasp
I read through this very interesting q/a about how computers reboot , and although
I read about the dynamic control creation in ASP.NET this piece of text: ...When
I read about creating user groups, I think I have the general idea. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.