answersLogoWhite

0


Best Answer

Processes do not execute, it is the threads within a process that actually execute. All processes have at least one thread of execution, the main thread. If the main thread falls from scope, the process ends, taking all threads with it. This can lead to undefined behaviour if the threads are not terminated gracefully from within the main thread before it falls from scope.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Yes, the thread will also terminate if the process it is running in terminates. The thread is dependent upon the processes it is running. If the processes die the thread dies.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If process stop its execution will thread also stop or it will continue to run?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is main method a thread?

No, Main is not a daemon thread in Java. its a non daemon or user thread. Also any thread stem from Main will be non daemon because daemon is derived from parent Thread status.


Can the subroutines of a high level language be called processes?

No. A subroutine (also known as a procedure or function) is best thought of as being a task. The executable (program) is the actual process. Every process has at least one thread of execution and each thread has its own local call stack. Thus multiple threads may concurrently execute the same task independently of any other threads within the same process. This is useful when we have a large or time-consuming task which can be broken down or divided up into smaller instances of the same task; each thread handles a small portion of the overall task and operates concurrently with all other instances of that task. Depending on how many CPU cores we have available, multiple threads of execution should complete the whole task quicker than a single thread would have. That is, if we divide the task into four, we could potentially complete the whole task in 1/4 of the time it would take with just one thread of execution.


What happens to child thread when you delete main thread during run-time?

In Java, if the main thread somehow exits then all other threads will stop executing. This generally does not happen, as the main thread will wait for all child threads to terminate before the main thread itself finishes. Interrupting this process is hard to do short of an un-handled exception or a call to System.exit. If the child thread is also a daemon thread, then the child thread will continue to execute. If the child thread is a normal thread then, the moment System.exit is called, the child thread also terminates If you call the join() method from the child thread, then the main thread will wait until the child is over before executing the System.exit


What is the relation between a thread and a process?

Threads exist within the same process; they can share memory and take less time to perform a "context switch;" they are part of the same program running in parallel processing units. Threads each have their own dedicated memory, and a shared memory area. Processes are entirely partitioned units of executing code. They cannot directly share memory with each other without assistance from the operating system, and are protected from each other by the operating system (in most modern operating systems, that is). They require more time to perform a context switch, as the entire task must be swapped out of the CPU instead of just the thread stack.


What is the difference between a Parent Process and Foreground Process?

A parent process is a process that has spawned one or more child processes such that it takes "ownership" of those processes. A foreground process typically means a process that has a user-interface as opposed to a background process which typically does not. Most background processes are services while most foreground processes are applications. It's important to note that the term "process" has a specific meaning in a multi-processing environment. A process is a computer program that has one or more threads of execution. A thread is the machine-level representation of a task and a process may instantiate as many tasks as are required (hardware permitting). All tasks share the same memory space as the process itself, however each task has its own stack for local storage, as well as to enable the thread's function call-and-return mechanism in addition to thread-local exception handling. Every process must have at least one thread of execution typically referred to as the main thread because that is the thread that executes the program's global main function (the entry point of the application) and subsequently instantiates any additional threads required by the main thread. The additional threads are usually called worker threads and any thread can instantiate its own worker threads. Unlike parent/child processes, thread's cannot "own" other threads; the threads are owned by the process. However, it is possible for worker threads to be controlled by other threads in the same process, so in that sense the controlling thread can be said to be a parent thread. When the main function returns, the main thread terminates, however any active threads within the process will continue executing, thus keeping the process "alive". In many cases this would be undesirable particularly if those threads attempt to access shared memory that is released by the main thread. So although there is no notion of ownership amongst threads, any controlling thread that must terminate before its workers have completed their tasks should signal its workers to terminate and then wait for them to terminate before terminating itself. Threads of execution within a process execute concurrently. All this means is that the operating system's task scheduler gives each thread a time-slice of the CPU to do some work, before saving the thread's state and moving onto the next thread (which may belong to another process entirely). Task-switching is so rapid that it can appear as though all threads are executing simultaneously, however that is only physically possible when the CPU has 2 or more cores available. Only one thread may execute upon any single core at any given moment. Multiple threads are typically used to maintain responsiveness. In a GUI environment, a time-consuming task would take up the entire time-slice of a process so it won't be able to respond to any messages on the message queue unless the task specifically checks the queue periodically. However, by using a worker thread to carry out the task, the controlling thread can remain responsive to messages. The message queue can also be used by threads to signal other threads, thus a controlling thread can respond to periodic progress reports from its worker threads if required. In this sense it can be said that the worker threads are background tasks, while the controlling thread is the foreground task.

Related questions

What is the Difference between a single threaded file server and a multi-threaded file server?

Single thread means that the processor will wait until one 'process' is complete before it opens a new thread or 'process'. Multi-thread can handle multiple threads simultaneously making it faster and more responsive.


If a process terminates will its thread also terminates?

Yes, the thread will also terminate if the process it is running in terminates. The thread is dependent upon the processes it is running. If the processes die the thread dies.


If a process terminates will its thread also terminate?

yes, because if process is terminated then its related thread has no work. After completion of process the kernel generates a thread that will cancelled the thread in order to save the time and memory of CPU.


Is main method a thread?

No, Main is not a daemon thread in Java. its a non daemon or user thread. Also any thread stem from Main will be non daemon because daemon is derived from parent Thread status.


How is the execution context of a process used by the operating system?

Also known as the process state, the execution context is the internal data the Operating system uses to control or supervise a process.


Can the subroutines of a high level language be called processes?

No. A subroutine (also known as a procedure or function) is best thought of as being a task. The executable (program) is the actual process. Every process has at least one thread of execution and each thread has its own local call stack. Thus multiple threads may concurrently execute the same task independently of any other threads within the same process. This is useful when we have a large or time-consuming task which can be broken down or divided up into smaller instances of the same task; each thread handles a small portion of the overall task and operates concurrently with all other instances of that task. Depending on how many CPU cores we have available, multiple threads of execution should complete the whole task quicker than a single thread would have. That is, if we divide the task into four, we could potentially complete the whole task in 1/4 of the time it would take with just one thread of execution.


What happens to child thread when you delete main thread during run-time?

In Java, if the main thread somehow exits then all other threads will stop executing. This generally does not happen, as the main thread will wait for all child threads to terminate before the main thread itself finishes. Interrupting this process is hard to do short of an un-handled exception or a call to System.exit. If the child thread is also a daemon thread, then the child thread will continue to execute. If the child thread is a normal thread then, the moment System.exit is called, the child thread also terminates If you call the join() method from the child thread, then the main thread will wait until the child is over before executing the System.exit


What is the relation between a thread and a process?

Threads exist within the same process; they can share memory and take less time to perform a "context switch;" they are part of the same program running in parallel processing units. Threads each have their own dedicated memory, and a shared memory area. Processes are entirely partitioned units of executing code. They cannot directly share memory with each other without assistance from the operating system, and are protected from each other by the operating system (in most modern operating systems, that is). They require more time to perform a context switch, as the entire task must be swapped out of the CPU instead of just the thread stack.


What is the difference between a Parent Process and Foreground Process?

A parent process is a process that has spawned one or more child processes such that it takes "ownership" of those processes. A foreground process typically means a process that has a user-interface as opposed to a background process which typically does not. Most background processes are services while most foreground processes are applications. It's important to note that the term "process" has a specific meaning in a multi-processing environment. A process is a computer program that has one or more threads of execution. A thread is the machine-level representation of a task and a process may instantiate as many tasks as are required (hardware permitting). All tasks share the same memory space as the process itself, however each task has its own stack for local storage, as well as to enable the thread's function call-and-return mechanism in addition to thread-local exception handling. Every process must have at least one thread of execution typically referred to as the main thread because that is the thread that executes the program's global main function (the entry point of the application) and subsequently instantiates any additional threads required by the main thread. The additional threads are usually called worker threads and any thread can instantiate its own worker threads. Unlike parent/child processes, thread's cannot "own" other threads; the threads are owned by the process. However, it is possible for worker threads to be controlled by other threads in the same process, so in that sense the controlling thread can be said to be a parent thread. When the main function returns, the main thread terminates, however any active threads within the process will continue executing, thus keeping the process "alive". In many cases this would be undesirable particularly if those threads attempt to access shared memory that is released by the main thread. So although there is no notion of ownership amongst threads, any controlling thread that must terminate before its workers have completed their tasks should signal its workers to terminate and then wait for them to terminate before terminating itself. Threads of execution within a process execute concurrently. All this means is that the operating system's task scheduler gives each thread a time-slice of the CPU to do some work, before saving the thread's state and moving onto the next thread (which may belong to another process entirely). Task-switching is so rapid that it can appear as though all threads are executing simultaneously, however that is only physically possible when the CPU has 2 or more cores available. Only one thread may execute upon any single core at any given moment. Multiple threads are typically used to maintain responsiveness. In a GUI environment, a time-consuming task would take up the entire time-slice of a process so it won't be able to respond to any messages on the message queue unless the task specifically checks the queue periodically. However, by using a worker thread to carry out the task, the controlling thread can remain responsive to messages. The message queue can also be used by threads to signal other threads, thus a controlling thread can respond to periodic progress reports from its worker threads if required. In this sense it can be said that the worker threads are background tasks, while the controlling thread is the foreground task.


Can the run method be called directly to start a thread?

No. If you want to start a new thread of execution, you need to call the start() method of the thread. Also, the run() is like any other java method and you can invoke it directly but if you do so, it would be called as part of the current programs thread and not as a new thread. When the start() method is invoked, the JVM creates a new thread and automatically calls the run() method and that is why a new thread gets started and not by calling run() directly.


What is the difference between LWP and threads?

This explains the difference between LWP-Process-Thread:A light-weight process (LWP) is a means of achieving multitasking. In contrast to a regular (full-blown) process, an LWP shares all (or most of) its logical address space and system resources with other process(es); in contrast to a thread, a light-weight process has its own private process identifier and parenthood relationships with other processes. Moreover, while a thread can either be managed at the application level or by the kernel, an LWP is always managed by the kernel and it is scheduled as a regular process. One significant example of a kernel that supports LWPs is the Linux kernel. On most systems, a light-weight process also differs from a full-blown process, in that it only consists of the bare minimum execution context and accounting information that is needed by the scheduler, hence the term light-weight. Generally, a process refers to an instance of a program, while an LWP represents a thread of execution of a program (indeed, LWPs can be conveniently used to implement threads, if the underlying kernel does not directly support them). Since a thread of execution does not need as much state information as a process, a light-weight process does not carry such information. As a consequence of the fact that LWPs share most of their resources with other LWPs, they are unsuitable for certain applications, where multiple full-blown processes are needed, e.g. to avoid memory leaks (a process can be replaced by another one) or to achieve privilege separation (processes can run under other credentials and have other permissions). Using multiple processes also allows the application to more easily survive if a process of the pool crashes or is exploited.


Difference between break and continue statements in wml?

Break statements:-its terminates the current while or for loop and continue the program execution from the statement following the terminated.NOTE:-note that it is wmlscript syntax error to use the break statement outside of while or a for statements.example;Breakstatement:Break;Continue statement:-this statement terminate execution of a block of statementin while or for loop and continues execution of loop with the next iteration.note that the continue statement does not terminate the execution of loop and also is wmlscript syntax error to use the break statement outside of while or a for statements.-> in while loop, it jumps back to the condition.-> in for loop,it jumpsto the update expression.syntax:continuestatement:continue;