answersLogoWhite

0

You use a process when you want a separate program, and a thread when you want to asynchronously execute some different code contained within the same program.

A process is an address space containing instructions, data, stack, etc. It represents one load module (or program) loaded into memory, ususally by the operating system's exec or equivalant call.

There can be more than one process loaded from the same load module. They are separate and distinct, even though they might share regions of instructions and constant data. As an example, the execution of ksh (in linux) or cmd (in windows) represents a process.

While executing, a process can invoke another process, either a copy of itself or a different one. For example, ksh can invoke ls, and cmd can invoke explorer. Keep in mind that this is still a different address space. In the case of linux, the process actually makes a copy of itself (fork) and then overlays itself with the new load module.

A thread, on the other hand is an execution path through a process. Every process has at least one thread, which starts with the first instruction it executes after being loaded, and ends with the call to the exit or equivalent operating system call.

So, to clarify, what executes is actually called a thread, and the process is just the address space. Different naming conventions do exist - this is the windows (and some other OS's) convention.

{Restating from three paragraphs before} While executing, a thread can load another process, either a copy of its containing process or a different one, or it can invoke a new thread within itself. While the difference might seem slight, it is not, because the (now two) threads share the same address space, and they can easily communicate with each other, assuming appropriate synchronization is used.

In the case of linux, you could say that a separate process is started as fork followed by overlay, while a new thread started as fork without the overlay.

Each thread has its own copy of its local variables, and a copy of the invoking parameters. In the simple case, that is sufficient. In the more complex case, involving explicitly allocated heap memory, either different heaps are used, or a mechanism for synchronized sharing is implemented.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Why is single thread system not used in java?

Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.


What is the difference between processes and threads?

The memory space, where a given application is executed is called - process. A Process is the memory set aside for an application to be executed in. Within this process the thing, which is really executed is the thread. The key difference is that processes are fully isolated from each other; threads share (heap) memory with other threads running in the same application. Threads share the address space of the process that created it; processes have their own address. Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process. Threads can directly communicate with other threads of its process; processes must use inter-process communication to communicate with sibling processes. Threads have almost no overhead; processes have considerable overhead. New threads are easily created; new processes require duplication of the parent process. Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes. A great answer to the question can also be found here: (link moved to link section)


What is the purpose of Java sleep?

It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.


Can a multithread solution using multiple user level threads achieve better performance on a multiprocessor system than on a single processor system?

A multithreaded system comprising of multiple user-levelthreads cannot make use of the different processors in a multiprocessorsystem simultaneously. The operating system sees only a single processand will not schedule the different threads of the process on separateprocessors. Consequently, there is no performance benefit associatedwith executing multiple user-level threads on a multiprocessor system.


What are the advantages of threads over processes?

Threads in distributed applications have the same benefits as in any other application: they allow you to perform multiple operations at the same time. Specifically for distributed applications, the server will most definitely be multi-threaded so that it can communicate with all of the clients. The clients will also most likely have at least two threads: one for communication with the server and one for doing actual data processing.

Related Questions

What can thread make?

In computer programming, you can use multiple threads if you want the computer to do several things at the same time.In computer programming, you can use multiple threads if you want the computer to do several things at the same time.In computer programming, you can use multiple threads if you want the computer to do several things at the same time.In computer programming, you can use multiple threads if you want the computer to do several things at the same time.


What is the support and use of multiple processors to handle multiple threads known as?

multiprocessing


The support and use of multiple processors to handle multiple threads is known as?

multiprocessing


What is The support and use of multiple processors to handle multiple threads is known as?

multiprocessing


Why is single thread system not used in java?

Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.Because the developers of Java considered the possibility of multithreading a big advantage. You don't HAVE TO use multiple threads; just use it when you need it.


How can I efficiently execute a Python run loop in parallel?

To efficiently execute a Python run loop in parallel, you can use libraries like multiprocessing or threading to create multiple processes or threads that run simultaneously. This allows you to take advantage of multiple CPU cores and speed up the execution of your loop. Be sure to carefully manage shared resources and handle synchronization to avoid conflicts between the parallel processes or threads.


What is the difference between processes and threads?

The memory space, where a given application is executed is called - process. A Process is the memory set aside for an application to be executed in. Within this process the thing, which is really executed is the thread. The key difference is that processes are fully isolated from each other; threads share (heap) memory with other threads running in the same application. Threads share the address space of the process that created it; processes have their own address. Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process. Threads can directly communicate with other threads of its process; processes must use inter-process communication to communicate with sibling processes. Threads have almost no overhead; processes have considerable overhead. New threads are easily created; new processes require duplication of the parent process. Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes. A great answer to the question can also be found here: (link moved to link section)


What is a multiple generator?

Multiple generators are when you use several smaller generators instead of one larger one. For example, you might use multiple 10Kw generators instead of one 30Kw generator.


How can you parallelize a for loop in Python effectively?

To parallelize a for loop in Python effectively, you can use libraries like multiprocessing or concurrent.futures to create multiple processes or threads to execute the loop iterations concurrently. This can help improve performance by utilizing multiple CPU cores. Be cautious of shared resources and synchronization to avoid race conditions.


Briefly summarise the reasons for the decisions made by software developers regarding the use of processes versus threads?

Control and speed of executions.


What are other words to use instead of steps?

phases, levels, processes, points.


What is the purpose of Java sleep?

It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.It pauses the execution of the program (or of the thread where it is invoked, if you have multiple threads), for the specified time.