1833275 Members
2784 Online
110051 Solutions
New Discussion

Run process

 
SOLVED
Go to solution
O'lnes
Regular Advisor

Run process

We have 2 CPU in our linux system, how can i assign both CPUs to run one large process cooperatively.
Andy
4 REPLIES 4
U.SivaKumar_2
Honored Contributor
Solution

Re: Run process

Hi,
All latest linux kernels support multiprocessing internally. You need not do anything. 2 CPUs will utilised almost equally
by the linux kernel automatically. Therefore
we say linux can support SMP symmetrical multi
processing.

regards,
U.SivaKumar
Innovations are made when conventions are broken
Bill Thorsteinson
Honored Contributor

Re: Run process

You can't assign one large
single-threaded process to
both CPUs. You need to
make the process multi-threaded
before you can use more than
1 CPU for a process. Not all
tasks are well suited for
multiprocessing.

O'lnes
Regular Advisor

Re: Run process

how to make one process to be multi-threaded? Thanks.
Andy
U.SivaKumar_2
Honored Contributor

Re: Run process


Hi,
A program or process can contain multiple threads that execute instructions according to program code. Like multiple processes that can run on one computer, multiple threads appear to be doing their work in parallel. Implemented on a multi-processor machine, they actually can work in parallel. Unlike processes, threads share the same address space; that is, they can read and write the same variables and data structures.

When you're writing multithreaded programs, you must take great care that no one thread disturbs the work of any other thread. You can liken this approach to an office where the workers function independently and in parallel except when they need to use shared office resources or communicate with one another. One worker can speak to another worker only if the other worker is "listening" and they both speak the same language. Additionally, a worker can't use a copy machine until it is free and in a useable state (no half-completed copy jobs, paper jams, and so on). As we work through this article, you'll see how you can get threads to coordinate and cooperate in a Java program much like workers in a well-behaved organization.

In a multithreaded program, threads are obtained from the pool of available ready-to-run threads and run on the available system CPUs. The OS can move threads from the processor to either a ready or blocking queue, in which case the thread is said to have "yielded" the processor. Alternatively, the Java virtual machine (JVM) can manage thread movement -- under either a cooperative or preemptive model -- from a ready queue onto the processor, where the thread can begin executing its program code.

Cooperative threading allows the threads to decide when they should give up the processor to other waiting threads. The application developer determines exactly when threads will yield to other threads, allowing them to work very efficiently with one another. A disadvantage is that a malicious or poorly written thread can starve other threads while it consumes all available CPU time.

Under the preemptive threading model, the OS interrupts threads at any time, usually after allowing them to run for a period of time (known as a time-slice). As a result, no thread can ever unfairly hog the processor. However, interrupting threads at any time poses problems for the program developer. Using our office example, consider what would happen if a worker preempts another worker making copies halfway through her copy job: the new worker would start his copy job on a machine that already has originals on the glass or copies in the output tray. The preemptive threading model requires that threads use shared resources appropriately, while the cooperative model requires threads to share execution time. Because the JVM specification does not mandate a particular threading model, Java developers must write programs for both models. We'll see how to design programs for either model after looking a bit at threads and communication among threads.

regards,
U.SivaKumar

Innovations are made when conventions are broken