What is the difference between a subprocess and a thread? I googled but was not able to find a suitable answer. The link for answer provided above differentiates between a process and thread but I want to know what the difference is between a subprocess and a thread. As a subprocess is also a process it will be mostly the same as the differences between a process and a thread but I want to know if there are some particular differences between a subprocess and thread which are not between a process and a thread.
First, we have to understand what actually the Process is, then Thread, if we could do that, then answer of this question will be easier.
Process vs. Thread
A process (also sometimes referred to as a task) is an executing (i.e., running) instance of a program. Threads are lightweight processes that can run in parallel and share an address space (i.e., a range of memory locations) and other resources with their parent processes (i.e., the processes that created them).
Above part is taken from this link: http://www.linfo.org/context_switch.html
A process is a program in execution. For example, when we write a program in C or C++ and compile it, the compiler creates a binary code. The original code and Binary code, both are programs. When we actually run the binary code, it becomes a process. A process is an ‘active’ entity as opposed to a program which is considered to be a ‘passive’ entity. A single program can create many processes when run multiple times, for example when we open a .exe or binary file multiple times, many instances begin (many processes are created).
Above part is taken from this link: https://www.geeksforgeeks.org/gate-notes-operating-system-process-management-introduction/
A process is an instance of program (e.g. Jupyter notebook, Python interpreter). Processes spawn threads (sub-processes) to handle subtasks like reading keystrokes, loading HTML pages, saving files. Threads live inside processes and share the same memory space.
Example: Microsoft Word When you open Word, you create a process. When you start typing, the process spawns threads: one to read keystrokes, another to display text, one to autosave your file, and yet another to highlight spelling mistakes. By spawning multiple threads, Microsoft takes advantage of idle CPU time (waiting for keystrokes or files to load) and makes you more productive.
Above part is taken from this link: https://medium.com/@bfortuner/python-multithreading-vs-multiprocessing-73072ce5600b
Python provide thread and subprocess library for the programmer for multitasking. The Purpose of both almost same but what we will choose thread or subproces depends on what we want. Threading maybe good enough for IO bound app, but not CPU bound app because it uses only SINGLE CPU core at once, because of Python's GIL and The failure of one thread would crash the whole app.
Subprocess is Good for both IO bound app and CPU bound app, but consuming more memory. Could use all the CPU core at the same time (parallel) and the failure of single process would not affect the others.
Above part is taken from this link: https://www.quora.com/For-multiprocessing-in-Python-which-library-should-I-use-threading-or-subprocess
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With