1

I have heard that programming languages like java have concept of multi threading .When i studied fork process in c language , i thought if it is an example of multi threading .

mrflash818
  • 930
  • 13
  • 24
  • 2
    Possible duplicate of [What is the difference between fork and thread?](https://stackoverflow.com/questions/2483041/what-is-the-difference-between-fork-and-thread) – DeiDei Jul 21 '18 at 16:27
  • Why did you delete your [most recent question](https://stackoverflow.com/questions/56913216/given-n-integers-in-a-round-fashion-how-to-choose-them-in-pairs-to-minimise-new) (and my answer with it)? – trincot Jul 06 '19 at 15:24

2 Answers2

5

No, it isn't. C doesn't even know fork(), but I assume you're talking about the POSIX function fork(). This creates a new process, which runs completely isolated (with a few exceptions like it can inherit open file descriptors) from the parent process.

For threading in C, have a look at the thread functions in C11. Unfortunately, the support for these isn't very widespread, but there's also the POSIX threading interface pthreads.

1

fork can be used to emulate threads (and it is certainly a way to introduce parallelism into a computation), but far fewer resources are shared with the parent process. On many systems, it is possible to share part of the address space by creating a MAP_SHARED mapping prior to forking, but apart from that, both processes are separate. Even file descriptors are only inherited—if you close them or open new ones, the other process is not affected by that.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92