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

  • Home
  • SEARCH
  • 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 8596501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:41:41+00:00 2026-06-12T00:41:41+00:00

I have this application which is a daemon program that detects and monitors devices.

  • 0

I have this application which is a daemon program that detects and monitors devices. It accepts arguments which then prints what devices are available. e.g.

 ./udevmon -s //prints the devices that are connected to my server.

Sample Output

 Device: /dev/ttyUSB0  subsystem: tty

Now when I run it again to check what devices are available, typing ./udevmon -s again it creates a second instace of ./udevmon with different process id. When I type ./udevmon without arguments it creates a new instance again with different process id so a total of 3 processrs of ./udevmon now. In time this will make my system slow because I need to run ./udevmon many times.

How can I run my application so it only creates a single instance. e.g restarting it when i type ./udevmon -s or ./udevmon again?

Here’s sample code.

int main (int argc, char *argv[])
{    
    mon_init();      // initialize device monitor
    scan_init();     // initialize device scan

    //Fork the Parent Process
    pid = fork();
    if (pid < 0) { exit(EXIT_FAILURE); }

    //We got a good pid, Close the Parent Process
    if (pid > 0) { exit(EXIT_SUCCESS); }

    //Change File Mask
    umask(0);

    //Create a new Signature Id for our child
    sid = setsid();
    if (sid < 0) { exit(EXIT_FAILURE); }

    //Change Directory
    //If we cant find the directory we exit with failure.
    if ((chdir("/")) < 0) { exit(EXIT_FAILURE); }

    while(( c=getopt(argc, argv,"s")) != -1) {
        switch(c) {
            case 's': scan_run(); break;
            default: printf("wrong command\n");
        }
    }

    //Main Process
    while(1) {
       start_mon();
    }
    udev_unref(udev);
    return 0;       
}
  • 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-12T00:41:42+00:00Added an answer on June 12, 2026 at 12:41 am

    Run your application under the following wrap instead:

    killall -KILL udevmon &> /dev/null
    ./udevmon <ARG>
    

    You may kill it softly using following script doing the same as above with some notifications:

    #!/bin/bash
    
    exist=`ps -e | grep udevmon | wc -l`
    
    if [ "$exist" == "0" ] ; then
    # there is no instance. run it
        echo "first run"
        ./udevmon -s
    else
    # kill old and run again
        pid=`ps -e | grep udevmon | awk '{print $1;}'`
        if [ "$pid" != "" ] ; then
            kill $pid
            echo "kill and run"
            ./udevmon -s
        else
            echo "unable to find pid!"
        fi
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scala application which is very simple . All that it does
I have this part of script from my GAE application which uses webapp2, which
I have an application which resides in ROOT. This application has a java class(in
We have a application which is triggered from browser. This application consumes around 800
In my c# application i have this small form which is used to set
I have a button in my application which is bound to a command. This
I have a .NET application which serializes an object in binary format. this object
I have one desktop application which was implemented in C#. This app uploads file
i'm building an android application which have a chat. in this chat i each
I am new to this iphone development.I have created a tab bar application which

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.