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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:34:06+00:00 2026-06-12T18:34:06+00:00

Possible Duplicate: fork in multi-threaded program If I have an application which employs fork()

  • 0

Possible Duplicate:
fork in multi-threaded program

If I have an application which employs fork() and might be developed as multithreaded, what are the thumb rules/guidelines to consider to safely program this kind of applications?

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

    The basic thumb rules, according to various internet articles like ( http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them , fork in multi-threaded program ) are:

    1. (Main) Process[0] Monothread –> fork() –> (Child) Process[1] Multithreaded: OK!
      If Process[1] crashes or messes around with memory it won’t touch address space of Process[0] (unless you use shared R/W memory… but this is another topic of its own).
      In Linux by default all fork()ed memory is Copy On Write. Given that Process[0] is monothreaded, when we invoke fork() all possible mutual exclusion primitives should be generally in an unlocked state.

    2. (Main) Process[0] Multithreaded –> fork() –> (Child) Process[1] Mono/Multithread: BAD!
      If you fork() a Multithreaded process your mutexes and many other thread synchronization primitives will likely be in an undefined state in Process[1]. You can work around with pthread_atfork() but if you use libraries you might as well roll a dice and hope to be lucky. Because generally you don’t (want to) know the implementation details of libraries.

    The advantages of fork() into a multithreaded process are that you could manipulate/read/aggregate your data quicker (in the Child process), without having to care about stability of the process you fork() from (Main). This is useful if your main process has a dataset of a lot of memory and you don’t want to duplicate/reload it to safely process the data in another process (Child). This way the original process is stable and independent from the data aggregation/manipulation process (fork()ed).

    Of course this means that the original process will generally be slower than it might be if developed in multithreaded fashion. But again, this is the price you might want to be paying for more stability.

    If instead your main process is multithreaded, refrain from using fork(). It’s going to be a proper mess to implement it in a stable way.

    Cheers

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

Sidebar

Related Questions

Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
So I have an application which uses threads. Now when the program first starts
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Does PHP have threading? I found this: http://php.net/manual/en/function.pcntl-fork.php But I can't tell
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Working of fork() in linux gcc Why does this code print two
Possible Duplicate: while( !feof( file ) ) is always wrong I have a strange
Possible Duplicate: How do you generate dynamic (parameterized) unit tests in Python? I have
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: What are the stages of compilation of a C++ program? I find

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.