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 8572123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:56:09+00:00 2026-06-11T18:56:09+00:00

I am executing a file as a daemon process. How can I stop the

  • 0

I am executing a file as a daemon process. How can I stop the daemon?

int main(int argc, char **argv)
{
    if ( argc != 5 )
    {
        printf ("Usage: %s <server> <nick> <channel> <logging>\n", argv[0]);
        return 1;
    }       
    char *startPath =  malloc(sizeof(char) *100);

strcpy(startPath,"/home/.../start");    

int child_pnr;

if(daemonisieren() != 0) 
{
    printf("damonization not possible");
    exit(0);
}   

printf("I am a damon \n");

 if((child_pnr = fork())==0)
{       
    execve(startPath,argv); 
}
else if (child_pnr > 0)
{   
    printf("I am parent and have a child \n");
    wait(child_pnr);
 }

printf("gone....\n");

free(startPath);
}

I presume I can kill it just like kill(childnr) but as the parent process waits for the child to finish execution which he may never do I have to have a program which knows the childnr and kills it. How can I do that?

  • 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-11T18:56:11+00:00Added an answer on June 11, 2026 at 6:56 pm

    You can make the child’s process number available using many different methods, all of which can be effective. A simple way is to just store it into a file on your system. If you look in /var/run you will probably find many XXX.pid files doing that already.

    Perhaps a better solution for your use case though is to start a new thread in your parent (or have it fork a second child) which performs a sleep for some amount of time and if that time elapses, it kills the primary child. If the primary child terminates on its own, satisfying the parent’s wait, the parent can kill the “watchdog” child (or thread).

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

Sidebar

Related Questions

I can get the currently executing file with the __FILE__ magic PHP constant, but
My code to daemonize a process is: static int daemonize( const char *lockfile )
In Python you can get the path of the file that is executing via
Possible Duplicate: Problem executing bash file I have created a bash file script and
Insertion of a file's tag, thus executing the file's code. Removal of the file's
I need to identify the P(rocess) ID of an executing batch file from a
I get unable to open database file when executing rc = sqlite3_open(test.db, &db); ??
I have a problem creating and executing a JAR file. I have already made
I'm currently having following error message when executing a .sql file with about 26MB
If I try executing the following code f = file('test','rb') fout = file('test.out','wb') 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.