doubt regarding os threads

Status
Not open for further replies.
Only the calling thread.
 

Does fork()duplicate only the calling thread or all threads?
under Unix fork() creates a clone (copy) of the process and executes it concurrently with the parent. The only difference between the two processes is that fork returns the child process ID to the parent and zero to the child
 

fork is for processes not threads.
--
Amr
 

processes and threads are different things.
A process is program in execution made up of heap, stack, fixed data, code, registers, etc.
fork() creates a clone (a copy) of a process and runs the parent and child concurrently, i.e. you have two copies of the same program executing at the same time (on a single CPU machine they will time share).

When new thread is created it uses the same address space as the parent process, i.e. they share code and global variables – but have own local variables.
It is still one process but with two internal threads of control, i.e. the threads can read/write data from/to the same variable in the memory of the process.
Of course you can then fork() it and have two processes each with two threads of control.
 
Reactions: arthur0

    arthur0

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…