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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:57:00+00:00 2026-06-06T09:57:00+00:00

I have a unstable program that kept crashing randomly, I could use a bash

  • 0

I have a unstable program that kept crashing randomly, I could use a bash script to keep it running, but is there a way to monitor it’s state ? Not by polling, but event-driven.

And and optional question, what if the monitor process isn’t the parent process of it, is this still possible ?

  • 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-06T09:57:02+00:00Added an answer on June 6, 2026 at 9:57 am

    You can write a simple wrapper which forks and execs the crashing process, and just wakes up when it gets SIGCHLD and starts all over again; conceptual code below:

    volatile sig_atomic_t gotchld = 0;
    
    void
    sigchld_handler(int sig)
    {
        if (sig == SIGCHLD)
            gotchld = 1;
    }
    
    signal(SIGCHLD, sigchld_handler);
    
    for (;;) {
        switch ((pid = fork()) {
        case -1:
            err(1, "fork");
        case 0:
            exec_my_crashy_program_here();
            errx(1, "came back from exec!");    /* paranoia */
        default:
            printf("sleeping for pid %u\n", pid);
            while (!gotchld)
                select(0, NULL, NULL, NULL, NULL);  /* sleep forever waiting for signal */
            /* possibly do fancy stuff with the wait() family of functions */
            gotchild = 0;
            continue;    
        }
    }
    

    You don’t need anything fancy, just a basic knowledge of how child and parent processes interact via signals.

    Please also consider that it’s been a while since I’ve dealt with signal stuff directly, so double-check that the code there is correct.

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

Sidebar

Related Questions

I have a gVIM script that parses current buffer and offers user to select
I have a program spawning and communicating with CPU heavy, unstable processes, not created
I have considered SQLite , but from what I've read, it is very unstable
Is there an exec variant that will use the current application directory to locate
I've written a simple application that works with database. My program have a table
Is there anyway to have a client side small database that syncs with server
I have a somewhat unstable internet connection. I'd like to have the Flex 3
I have a big application as an enterprise scale, there are lots of developers
I have tried macports: port install openvrml Also tried fink (with unstable tree configuration)
We have WebRole, that hosting multiple sites. We made startup tasks for each site

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.