简体   繁体   中英

C/C# fork vs thread vs bg worker?

I learnt about fork() and execv() in c and many other system calls and still some things aren't that clear to me.

A while ago I wrote a C# program where I used threads to make my program update the database without making the UI freeze. are processes different that C threads, and are they different than C# threads or background workers.

I am totally lost in this. why we need fork() when that's what thread does.

why we need fork() when that's what thread does.

fork() and threads solve different problems.

fork() is an older parallel programming paradigm that spawns child processes that inherit memory from the parent, but don't share it like threads do (writes to the memory only change the memory in one process, not the others). While this model of parallel programming is largely superseded by threads, it is still useful when isolation is required.

In addition to the above, fork() can be used with exec() to start different executables and build pipelines between them. This use of fork() is still relevant and is how Unix shells implement complex commands like sort | uniq | wc -l sort | uniq | wc -l sort | uniq | wc -l .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM