fork vs. exec vs thr_create

fork vs. exec vs thr_create

Post by <U64.. » Thu, 29 Sep 1994 09:57:39



As a "single process programmer" , I've recently begin to look
at fork and the collection of exec calls. Doing so I came across
a Solaris command "thr_create" which creates a new thread. Now I'm
confused, how is a thread different from a (child) process created
by a fork and folowed by an exec?
Thanks in advance.
--------------------
Thaddeus L. Olczyk
 
 
 

fork vs. exec vs thr_create

Post by Jim Troc » Thu, 29 Sep 1994 22:05:55



Quote:>As a "single process programmer" , I've recently begin to look
>at fork and the collection of exec calls. Doing so I came across
>a Solaris command "thr_create" which creates a new thread. Now I'm
>confused, how is a thread different from a (child) process created
>by a fork and folowed by an exec?
>Thanks in advance.
>--------------------
>Thaddeus L. Olczyk

  fork(2) creates an image of the currently running process in memory with
its own process ID. This new process has its own page tables, but shares file
handles and other things with the parent process.

 A thread, on the other hand, shares its page table with the parent process,
in an attempt to increase efficiency by reducing the context-switch time.
When the OS does a context switche to a thread, it doesn't need to re-load
info about page tables for that "process".

Jim Trocki


 
 
 

fork vs. exec vs thr_create

Post by Michael Salm » Thu, 29 Sep 1994 19:32:50




|> As a "single process programmer" , I've recently begin to look
|> at fork and the collection of exec calls. Doing so I came across
|> a Solaris command "thr_create" which creates a new thread. Now I'm
|> confused, how is a thread different from a (child) process created
|> by a fork and folowed by an exec?

A thread is also called a light weight process. Threads belong to a
process and share their address space. This basically means that
information is shared unless you do something to prevent it.  A forked
process however has a separate address space which means that
information is not-shared unless you do something about it. Swapping
threads takes less time than swapping processes which is good but
threads are more complex to code, as an example errno can no longer be
a variable as another thread may have changed it value before your
thread reads it.

--

Michael Salmon

#include        <standard.disclaimer>
#include        <witty.saying>
#include        <fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm

 
 
 

fork vs. exec vs thr_create

Post by <U64.. » Fri, 30 Sep 1994 00:45:53


My apologies. The question should be what is the difference between fork

and thr_create. They both seem to create new threads.
------------------------
Thaddeus L. Olczyk

 
 
 

fork vs. exec vs thr_create

Post by Robert List » Sat, 01 Oct 1994 03:00:03





> |> As a "single process programmer" , I've recently begin to look
> |> at fork and the collection of exec calls. Doing so I came across
> |> a Solaris command "thr_create" which creates a new thread. Now I'm
> |> confused, how is a thread different from a (child) process created
> |> by a fork and folowed by an exec?

> A thread is also called a light weight process. Threads belong to a
> process and share their address space. This basically means that
> information is shared unless you do something to prevent it.  A forked
> process however has a separate address space which means that
> information is not-shared unless you do something about it. Swapping
> threads takes less time than swapping processes which is good but
> threads are more complex to code, as an example errno can no longer be
> a variable as another thread may have changed it value before your
> thread reads it.

> --

> Michael Salmon

> #include   <standard.disclaimer>
> #include   <witty.saying>
> #include   <fancy.pseudo.graphics>

> Ericsson Telecom AB
> Stockholm

My understanding is that each process can contain many LWPs and each
LWP can contain many threads.  The process provides the address space.
LWPs are scheduled preemptively within a process.
Threads are scheduled non-preemptively within an LWP.
So the only way to make a preemptively scheduled thread is to give it
an LWP of it own (THR_BOUND | THR_NEW_LWP).

These are empirical observations based on some fiddling I have done,
so take them with a grain of salt.


 
 
 

1. Linux vs OS2 vs NT vs Win95 vs Multics vs PDP11 vs BSD geeks

        Every machine and operating system has got its useful
purpose...

        I see no point in argueing with people which OS is better, and
which is worse, and what will survive and what wont...

        The bottom line is obviously the best OS is the one that make
the end user most productive.    Ive used quite a variety of software
from intel, ibm, MS, sun, GNU, DEC/compaq, etc,   and everything OS
has got its UPz and DOWnz, so depending on what you want to do with it
yer machine, probably determines what OS you run.

        So lets cut to the chase -  OS bashing is a waste of time,
and most of the time I'd say the person putting it down just hasn't
seen that particular OS's potential,  or should I say speciality....

      Hell,  Plan 9 has even got some interesting features.. <snicker>

       And all PC users know,  that no matter what use on a day to day
basis on the PC, that one day you will need to boot good ole ancient
DOS to do something...

2. Software Development Tools

3. Efficiency: fork() w/ shared libraries vs. fork()/exec()

4. Frozen Netscape

5. Perfomance: tar vs ftp vs rsync vs cp vs ?

6. where are Mosaic binaries for ELF?

7. Slackware vs SuSE vs Debian vs Redhat vs ....

8. nameserver config

9. DOS vs. Windows vs. Mac vs. Unix vs. NS

10. KDE vs. Openlook vs. Xfree86 vs. MetroX vs. CDE

11. Redhat vs Debian vs Yggdrasil vs Caldera vs ...

12. system() vs. fork/exec/waitpid

13. BSD vs S5 vs MACH vs OSF/1 (no religion, please!)