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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:36:37+00:00 2026-05-13T08:36:37+00:00

I’m working on an audio encoder cgi script that utilises libmp3lame. I’m writing in

  • 0

I’m working on an audio encoder cgi script that utilises libmp3lame.
I’m writing in a mixture of C/C++.

I plan to have an entry-point cgi that can spawn multiple encoding processes that run in the background. I need the encoding processes to be asynchronous as encoding can take several hours but I need the entry-point cgi to return instantly so the browser can continue about its business.

I have found several solutions for this (some complete/ some not) but there are still a few things I’d like to clear up.

Solution 1 (easiest): The entry-point cgi is a bash script which can then run a C++ process cgi in the background by sending the output to /dev/null/ 2/&>1& (simples! but not very elegant).

Solution 2: Much like solution 1, except the entry-point cgi is in C++ and uses system() to run the proc/s and send the output to /dev/null/ 2/&>1& again.

[question] This works well but I’m not sure if shared hosting companies allow use of the system() function. Is this the case?

Solution 3 (incomplete): I’ve looked into using fork()/pthread_create() to spawn separate threads which seems more elegant as I can stay in the realms of C. The only problem being: It seems that the parent thread doesn’t exit until all child threads have returned.

[question] Is there any way to get the parent thread to exit whilst allowing child threads to continue in the background.

[idea] Maybe I can send the child proc/s output to the black hole! Can I simply redirect stdout to /dev/null. If so, how do I do this?

I hope this makes sense to someone. I’m still a bit of a noob with C stuff so I may be missing very basic concepts (please have mercy!).

I’d be very grateful of any advise on this matter.

Many thanks in advance,

Josh

  • 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-05-13T08:36:38+00:00Added an answer on May 13, 2026 at 8:36 am

    You probably want the standard Unix daemon technique, involving a double fork:

    void daemonize(void)
    {
      if (fork()) exit(0); // fork.  parent exits.
      setsid(); // become process group leader
      if (fork()) _exit(0); // second parent exits.
      chdir("/"); // just so we don't mysteriously prevent fs unmounts later
      close(0); // close stdin, stdout, stderr.
      close(1);
      close(2);
    }
    

    Looks like modern Linux machines have a daemon() library function that presumably does the same thing.

    It’s possible that the first exit should be _exit, but this code has always worked for me.

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

Sidebar

Ask A Question

Stats

  • Questions 413k
  • Answers 413k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use levels() to reset the factor level you want to… May 15, 2026 at 8:22 am
  • Editorial Team
    Editorial Team added an answer You need to call testControl.DataBind() in code. <%# gets set… May 15, 2026 at 8:22 am
  • Editorial Team
    Editorial Team added an answer I think deleting the "deploy/hdscanner-jboss-beans.xml" file is the correct way… May 15, 2026 at 8:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.