in reply to use dual-core or quad-core
The following is for Linux (and should work this way on most *NIXes).
To have your program use one core only all you need to do is run it without forking. The OS will automatically give you as much CPU time on a single core as it can without detrimentally affecting the rest of the system. This means that, unless you're on a system that is heavily loaded by multiple processes (or your program is I/O-bound) your program will always run at 99% or 100% CPU usage on a multi-core machine. If you find that the OS scheduler occasionally assigns other tasks to the core your program is using (if e.g. you're on a desktop system which has several programs you're using interactively) you can change the process priority (the "nice" value) via the inbuilt setpriority(e.g. setpriority 0,$$,1)
For running your process on multiple CPU cores, simply fork it into as many processes. Again, the OS will take care of running your processes efficiently. Executing setpriority prior to forking will pass the nice value on to the process children.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use dual-core or quad-core
by BrowserUk (Patriarch) on May 20, 2008 at 09:35 UTC | |
by tirwhan (Abbot) on May 20, 2008 at 09:55 UTC | |
by BrowserUk (Patriarch) on May 20, 2008 at 10:15 UTC |