Re: thread and process



asit <lipun4u@xxxxxxxxx> writes:
Linux treats threads like processes. Then what is the advantage of
thread over process??

Wikipedia isn't necessarily a reliable source of information :->.
As stated above, this sentence is nonsensical: A process is defined as
a set of system ressources, most prominently, an address space separate
from the address spaces of all other processes, shared by n threads of
execution, n >= 1.

At the implementation level, there are three different ways to
implement multithreading-support, called 1:1-threading, where each
thread of the process is visible to (and scheduled by) the scheduler
in the kernel, 1:n-threading, using a userspace scheduler for threads
the (process) scheduler in the kernel is completely unaware of, and
m:n-threading, utilizing two cooperating schedulers, with the kernel
scheduler 'seeing' m so-called 'light-weight processes' onto which the
userspace scheduler multiplexes n threads of execution (with m < n,
obviously). These were invented because a lot of the state information
associated with a traditionally implemented 'UNIX(*) process', eg
uids, gids, cwd, table of open files etc, must remain per-process in
multithreaded applicatins and because context-switching in userspace
has a lower overhead than trapping into the kernel to accomplish the
same. Since Linux is not UNIX(*), it didn't inherit the UNIX(*)
process implementation, so there was no need to create a separate
less-baggaged kernel abstraction for threads and the assumption that
the higher overhead of using a unified scheduler in the kernel would
matter practically turned out to be wrong: The Linux-kernel uses
something represented by a struct task_struct containing pointers to
shareable ressource structures internally to represent 'kernel
schedulable entities' and 'processes' exist only virtually, insofar as
a set of such tasks sharing certain ressource structures 'looks like'
a UNIX(*)-process to application code to some degree: For instance,
until Linux 2.6, such a virtual process didn't have an ID-number of
its own, only each of the tasks comprising it had one.

The reason some people (eg R. Love in 'Linux Kernel Development')
erronously claim that 'Linux threads are just processes' is because
this implementation evolved from the ancient (IIRC, pre-2.0) kernel
implementation of multi-process support, which exited at a time when
there was no kernel support for multi-threading in Linux.
.



Relevant Pages

  • Re: [ck] Re: Linus 2.6.23-rc1
    ... They replaced code because he would have liked to have taken scheduler code ... He's strong in this area and weak in general kernel ... day in Linux because of people's collective lack of foresight. ... community admitted that there was a problem earlier and permitted more ...
    (Linux-Kernel)
  • Re: [OT] Interview with Con Kolivas on Linux failures
    ... Con Kolivas, the kernel hacker who authored a better scheduler, recently decided to quit. ... Loss for Linux ... The former option means you have a CPU scheduler which is difficult to model, and the behaviour is right 95% of the time and ebbs and flows in its metering out of CPU and latency. ...
    (Debian-User)
  • Re: [patch, 2.6.11-rc2] sched: RLIMIT_RT_CPU_RATIO feature
    ... like fork/cloneand underlying kernel structures from what I see. ... as media apps get more sophisticated they're going to need some ... It would be nice to have slack from scheduler frames be use ... with the current Linux code as I understand it. ...
    (Linux-Kernel)
  • Re: Creating an operating system
    ... installed Red Hat Linux 6.0 for the first time, ... Of course only the kernel ... waste the first time trying to understand how it boots. ... I didn't understand how a scheduler really works before ...
    (comp.programming)
  • Re: Creating an operating system
    ... installed Red Hat Linux 6.0 for the first time, ... Of course only the kernel ... waste the first time trying to understand how it boots. ... I didn't understand how a scheduler really works before ...
    (comp.os.linux.development.system)