views:

643

answers:

5
+2  Q: 

Process and Thread

What is the data that Process and Thread will not share ?

An advance thanks goes to everybody who provide their time

+3  A: 

Separate processes do not share any data with each other.

Threads can share any heap-allocated or static data if they are running within the same process.

Adam Pierce
Not accurate. There is really no reason that data on the stack of one thread could not be shared with another thread so long the thead with the data doesn't return from the stack frame with the data.
shoosh
+2  A: 

It depends on the context. Completely separate processes do not share any of the same memory in most cases, but in some cases child processes will share the same memory space as the parent, such as when you use fork in Unix. In older version of Windows (95,98,ME) there's a shared memory area that is shared among all processes, but mainly it's just a space for system DLLs not data.

Generally threads share heap data, but you will want to be careful deallocating memory in one thread that was allocated in another thread since some memory managers depend on the stack.

Gerald
+1  A: 

BY default no sharing of Data between processes, But using Inter-process communication techniques such as Socket , Pipes, RPC etc..you can share the data.

Jobi Joy
A: 

On UNIX, processes can share file descriptors with their child processes if the file descriptors are not set to close on exec (FD_CLOEXEC). Likewise, Windows supports sharing handles with child processes by setting lpSecurityAttributes->bInheritHandle to TRUE when calling CreateFile() and then setting bInheritHandles to TRUE when calling CreateProcess. Not to mention that the Microsoft C runtime _open() function accepts a _O_NOINHERIT flag.

On Linux, the clone() syscall gives you a lot of control over what the child process shares with its parent: everything from the address space (CLONE_VM) to the file descriptor table (CLONE_FILES) to the parent process ID (CLONE_PARENT) can be either shared or not shared. Of course, this functionality was added to support kernel threads.

Thread-local storage (TLS) is indexed differently for each thread in a process, but the actual memory is shared between threads.

bk1e
+1  A: 

In operating system theory (and AFAIK this applies to operating systems such as Windows, Linux, *BSD, ...) a process is defined as a thread with its own page table, i.e. its own virtual memory space.

Anything else is OS dependant (file descriptors, sockets, etc.). In my experience, such thread properties are usually copied with standard system calls that replicate processes. Think about it, it's easier to implement and more resourceful too (less house keeping and keep non-virtual memory without touching it).

mstrobl