Detects body heat (infrared energy). Passive infrared sensors are the most widely used motion in home security systems. When your system is armed, your motion sensors are activated. Once the sensor warms up, it can detect heat and movement in the surrounding areas, creating a protective "grid." If a moving object blocks too many grid zones and the infrared energy levels change rapidly, the sensors are tripped.
MircoWave (MW):
Sends out microwave pulses and measures the reflection off a moving object. They cover a larger area than infrared sensors, but they are vulnerable to electrical interference and are more expensive.
Dual Technology Motion Sensors:
Motion sensors can have combined features in an attempt to reduce false alarms. For example, a passive infrared (PIR) sensor could be combined with a microwave sensor. Since each operates in different areas of the spectrum, and one is passive and one is active, Dual Technology motion sensors are not as likely as other types to cause false alarms, because in order for the alarm to be triggered, both sensors have to be tripped. However, this does not mean that they never cause false alarms.
Area Reflective Type:
Emits infrared rays from an LED. Using the reflection of those rays, the sensor measures the distance to the person or object and detects if the object is within the designated area.
Ultrasonic:
Sends out pulses of ultrasonic waves and measures the reflection off a moving object.
Vibration:
Detects vibration. These can be purchased or easily made at home. A homemade vibration sensor uses a small mass on a lever, which is activated by a switch to an alarm when it vibrates. Homemade motion sensors can work, but they can also be unreliable.
The 555 timer which gets its name from the three 5kΩ resistors it uses to generate the two comparators reference voltage, is a very cheap, popular and useful precision timing device that can act as either a simple timer to generate single pulses or long time delays, or as a relaxation oscillator producing stabilized waveforms of varying duty cycles from 50 to 100%.
The 555 timer chip is extremely robust and stable 8-pin device that can be operated either as a very accurate Monostable, Bistable or Astable Multivibrator to produce a variety of applications such as one-shot or delay timers, pulse generation, LED and lamp flashers, alarms and tone generation, logic clocks, frequency division, power supplies and converters etc, in fact any circuit that requires some form of time control as the list is endless.
The single 555 Timer chip in its basic form is a Bipolar 8-pin mini Dual-in-line Package (DIP) device consisting of some 25 transistors, 2 diodes and about 16 resistors arranged to form two comparators, a flip-flop and a high current output stage as shown below. As well as the 555 Timer there is also available the NE556 Timer Oscillator which combines TWO individual 555’s within a single 14-pin DIP package and low power CMOS versions of the single 555 timer such as the 7555 and LMC555 which use MOSFET transistors instead.
A simplified “block diagram” representing the internal circuitry of the 555 timer is given below with a brief explanation of each of its connecting pins to help provide a clearer understanding of how it works.
555 Timer Block Diagram
• Pin 1. –
Ground, The ground pin connects the 555 timer to the negative (0v) supply rail.
• Pin 2. –
Trigger, The negative input to comparator No 1. A negative pulse on this pin “sets” the internal Flip-flop when the voltage drops below 1/3Vcc causing the output to switch from a “LOW” to a “HIGH” state.
• Pin 3. –
Output, The output pin can drive any TTL circuit and is capable of sourcing or sinking up to 200mA of current at an output voltage equal to approximately Vcc – 1.5V so small speakers, LEDs or motors can be connected directly to the output.
• Pin 4. –
Reset, This pin is used to “reset” the internal Flip-flop controlling the state of the output, pin 3. This is an active-low input and is generally connected to a logic “1” level when not used to prevent any unwanted resetting of the output.
• Pin 5. –
Control Voltage, This pin controls the timing of the 555 by overriding the 2/3Vcc level of the voltage divider network. By applying a voltage to this pin the width of the output signal can be varied independently of the RC timing network. When not used it is connected to ground via a 10nF capacitor to eliminate any noise.
• Pin 6. –
Threshold, The positive input to comparator No 2. This pin is used to reset the Flip-flop when the voltage applied to it exceeds 2/3Vcc causing the output to switch from “HIGH” to “LOW” state. This pin connects directly to the RC timing circuit.
• Pin 7. –
Discharge, The discharge pin is connected directly to the Collector of an internal NPN transistor which is used to “discharge” the timing capacitor to ground when the output at pin 3 switches “LOW”.
• Pin 8. –
Supply +Vcc, This is the power supply pin and for general purpose TTL 555 timers is between 4.5V and 15V.
The 555 Timers name comes from the fact that there are three 5kΩ resistors connected together internally producing a voltage divider network between the supply voltage at pin 8 and ground at pin 1. The voltage across this series resistive network holds the negative inverting input of comparator two at 2/3Vcc and the positive non-inverting input to comparator one at 1/3Vcc.
The two comparators produce an output voltage dependant upon the voltage difference at their inputs which is determined by the charging and discharging action of the externally connected RCnetwork. The outputs from both comparators are connected to the two inputs of the flip-flop which in turn produces either a “HIGH” or “LOW” level output at Q based on the states of its inputs. The output from the flip-flop is used to control a high current output switching stage to drive the connected load producing either a “HIGH” or “LOW” voltage level at the output pin.
The most common use of the 555 timer oscillator is as a simple astable oscillator by connecting two resistors and a capacitor across its terminals to generate a fixed pulse train with a time period determined by the time constant of the RC network. But the 555 timer oscillator chip can also be connected in a variety of different ways to produce Monostable or Bistable multivibrators as well as the more common Astable Multivibrator.
The Monostable 555 Timer
The operation and output of the 555 timer monostable is exactly the same as that for the transistorised one we look at previously in the Monostable Multivibrators tutorial. The difference this time is that the two transistors have been replaced by the 555 timer device. Consider the 555 timer monostable circuit below.
Monostable 555 Timer
When a negative ( 0V ) pulse is applied to the trigger input (pin 2) of the Monostable configured 555 Timer oscillator, the internal comparator, (comparator No1) detects this input and “sets” the state of the flip-flop, changing the output from a “LOW” state to a “HIGH” state. This action in turn turns “OFF” the discharge transistor connected to pin 7, thereby removing the short circuit across the external timing capacitor, C1.
This action allows the timing capacitor to start to charge up through resistor, R1 until the voltage across the capacitor reaches the threshold (pin 6) voltage of 2/3Vcc set up by the internal voltage divider network. At this point the comparators output goes “HIGH” and “resets” the flip-flop back to its original state which in turn turns “ON” the transistor and discharges the capacitor to ground through pin 7. This causes the output to change its state back to the original stable “LOW” value awaiting another trigger pulse to start the timing process over again. Then as before, the Monostable Multivibrator has only “ONE” stable state.
The Monostable 555 Timer circuit triggers on a negative-going pulse applied to pin 2 and this trigger pulse must be much shorter than the output pulse width allowing time for the timing capacitor to charge and then discharge fully. Once triggered, the 555 Monostable will remain in this “HIGH” unstable output state until the time period set up by the R1 x C1 network has elapsed. The amount of time that the output voltage remains “HIGH” or at a logic “1” level, is given by the following time constant equation.
Where, t is in seconds, R is in Ω’s and C in Farads.
555 Timer Example No1
A Monostable 555 Timer is required to produce a time delay within a circuit. If a 10uF timing capacitor is used, calculate the value of the resistor required to produce a minimum output time delay of 500ms.
500ms is the same as saying 0.5s so by rearranging the formula above, we get the calculated value for the resistor, R as:
The calculated value for the timing resistor required to produce the required time constant of 500ms is therefore, 45.5KΩ’s. However, the resistor value of 45.5KΩ’s does not exist as a standard value resistor, so we would need to select the nearest preferred value resistor of 47kΩ’s which is available in all the standard ranges of tolerance from the E12 (10%) to the E96 (1%), giving us a new recalculated time delay of 517ms.
If this time difference of 17ms (500 – 517ms) is unacceptable instead of one single timing resistor, two different value resistor could be connected together in series to adjust the pulse width to the exact desired value, or a different timing capacitor value chosen.
We now know that the time delay or output pulse width of a monostable 555 timer is determined by the time constant of the connected RC network. If long time delays are required in the 10’s of seconds, it is not always advisable to use high value timing capacitors as they can be physically large, expensive and have large value tolerances, e.g, ±20%.
One alternative solution is to use a small value timing capacitor and a much larger value resistor up to about 20MΩ’s to produce the require time delay. Also by using one smaller value timing capacitor and different resistor values connected to it through a multi-position rotary switch, we can produce a Monostable 555 timer oscillator circuit that can produce different pulse widths at each switch rotation such as the switchable Monostable 555 timer circuit shown below.
A Switchable 555 Timer
We can manually calculate the values of R and C for the individual components required as we did in the example above. However, the choice of components needed to obtain the desired time delay requires us to calculate with either kilohm’s, Megaohm’s, microfarad’s or picafarad’s and it is very easy to end up with a time delay that is out by a factor of ten or even a hundred.
We can make our life a little easier by using a type of chart called a “Nomograph” that will help us to find the monostable multivibrators expected frequency output for different combinations or values of both the R and C. For example,
Monostable Nomograph
So by selecting suitable values of C and R in the ranges of 0.001uF to 100uF and 1kΩ to 10MΩ’s respectively, we can read the expected output frequency directly from the nomograph graph thereby eliminating any error in the calculations. In practice the value of the timing resistor for a monostable 555 timer should not be less than 1kΩ or greater than 20MΩ
Bistable 555 Timer
As well as the one shot 555 Monostable configuration above, we can also produce a Bistable (two stable states) device with the operation and output of the 555 Bistable being similar to the transistorised one we look at previously in the Bistable Multivibrators tutorial.
The 555 Bistable is one of the simplest circuits we can build using the 555 timer oscillator chip. This bistable configuration does not use any RC timing network to produce an output waveform so no equations are required to calculate the time period of the circuit. Consider the Bistable 555 Timer circuit below.
Bistable 555 Timer (flip-flop)
The switching of the output waveform is achieved by controlling the trigger and reset inputs of the 555 timer which are held “HIGH” by the two pull-up resistors, R1 and R2. By taking the trigger input (pin 2) “LOW”, switch in set position, changes the output state into the “HIGH” state and by taking the reset input (pin 4) “LOW”, switch in reset position, changes the output into the “LOW” state.
This 555 timer circuit will remain in either state indefinitely and is therefore bistable. Then theBistable 555 timer is stable in both states, “HIGH” and “LOW”. The threshold input (pin 6) is connected to ground to ensure that it cannot reset the bistable circuit as it would in a normal timing application.
555 Timer Output
We could not finish this 555 Timer tutorial without discussing something about the switching and drive capabilities of the 555 timer or indeed the dual 556 Timer IC.
The output (pin 3) of the standard 555 timer or the 556 timer, has the ability to either “Sink” or “Source” a load current of up to a maximum of 200mA, which is sufficient to directly drive output transducers such as relays, filament lamps, LED’s motors, or speakers etc, with the aid of series resistors or diode protection.
This ability of the 555 timer to both “Sink” (absorb) and “Source” (supply) current means that the output device can be connected between the output terminal of the 555 timer and the supply to sink the load current or between the output terminal and ground to source the load current. For example.
Sinking and Sourcing the 555 Timer Output
In the first circuit above, the LED is connected between the positive supply rail ( +Vcc ) and the output pin 3. This means that the current will “Sink” (absorb) or flow into the 555 timer output terminal and the LED will be “ON” when the output is “LOW”.
The second circuit above shows that the LED is connected between the output pin 3 and ground ( 0v ). This means that the current will “Source” (supply) or flow out of the 555 timers output terminal and the LED will be “ON” when the output is “HIGH”.
The ability of the 555 timer to both sink and source its output load current means that both LED’s can be connected to the output terminal at the same time but only one will be switched “ON” depending whether the output state is “HIGH” or “LOW”. The circuit to the left shows an example of this. the two LED’s will be alternatively switched “ON” and “OFF” depending upon the output. Resistor, R is used to limit the LED current to below 20mA.
We said earlier that the maximum output current to either sink or source the load current via pin 3 is about 200mA at the maximum supply voltage, and this value is more than enough to drive or switch other logic IC’s, LED’s or small lamps, etc. But what if we wanted to switch or control higher power devices such as motors, electromagnets, relays or loudspeakers. Then we would need to use aTransistor to amplify the 555 timers output in order to provide a sufficiently high enough power to drive the load.
555 Timer Transistor Driver
The transistor in the two examples above, can be replaced with a Power MOSFET device or Darlington transistor if the load current is high. When using an inductive load such as a motor, relay or electromagnet, it is advisable to connect a freewheeling (or flywheel) diode directly across the load terminals to absorb any back emf voltages generated by the inductive device when it changes state.
Thus far we have look at using the 555 Timer to generate monostable and bistable output pulses. In the next tutorial about Waveform Generation we will look at connecting the 555 in an astable multivibrator configuration. When used in the astable mode both the frequency and duty cycle of the output waveform can be accurately controlled to produce a very versatile waveform generator.
But we can also connect the 555 timer IC in an Astable mode to produce a very stable 555 Oscillatorcircuit for generating highly accurate free running waveforms whose output frequency can be adjusted by means of an externally connected RC tank circuit consisting of just two resistors and a capacitor.
The 555 Oscillator is another type of relaxation oscillator for generating stabilized square wave output waveforms of either a fixed frequency of up to 500kHz or of varying duty cycles from 50 to 100%. In the previous 555 Timer tutorial we saw that the Monostable circuit produces a single output one-shot pulse when triggered on its pin 2 trigger input.
Whereas the 555 monostable circuit stopped after a preset time waiting for the next trigger pulse to start over again, in order to get the 555 Oscillator to operate as an astable multivibrator it is necessary to continuously re-trigger the 555 IC after each and every timing cycle.
This re-triggering is basically achieved by connecting the trigger input (pin 2) and the thresholdinput (pin 6) together, thereby allowing the device to act as an astable oscillator. Then the 555 Oscillator has no stable states as it continuously switches from one state to the other. Also the single timing resistor of the previous monostable multivibrator circuit has been split into two separate resistors, R1 and R2 with their junction connected to the discharge input (pin 7) as shown below.
Basic Astable 555 Oscillator Circuit
In the 555 Oscillator circuit above, pin 2 and pin 6 are connected together allowing the circuit to re-trigger itself on each and every cycle allowing it to operate as a free running oscillator. During each cycle capacitor, C charges up through both timing resistors, R1 and R2 but discharges itself only through resistor, R2 as the other side of R2 is connected to the discharge terminal, pin 7.
Then the capacitor charges up to 2/3Vcc (the upper comparator limit) which is determined by the0.693(R1+R2)C combination and discharges itself down to 1/3Vcc (the lower comparator limit) determined by the 0.693(R2.C) combination. This results in an output waveform whose voltage level is approximately equal to Vcc – 1.5V and whose output “ON” and “OFF” time periods are determined by the capacitor and resistors combinations. The individual times required to complete one charge and discharge cycle of the output is therefore given as:
Astable 555 Oscillator Charge and Discharge Times
Where, R is in Ω’s and C in Farads.
When connected as an astable multivibrator, the output from the 555 Oscillator will continue indefinitely charging and discharging between 2/3Vcc and 1/3Vcc until the power supply is removed. As with the monostable multivibrator these charge and discharge times and therefore the frequency are independent on the supply voltage.
The duration of one full timing cycle is therefore equal to the sum of the two individual times that the capacitor charges and discharges added together and is given as:
555 Oscillator Cycle Time
The output frequency of oscillations can be found by inverting the equation above for the total cycle time giving a final equation for the output frequency of an Astable 555 Oscillator as:
555 Oscillator Frequency Equation
By altering the time constant of just one of the RC combinations, the Duty Cycle better known as the “Mark-to-Space” ratio of the output waveform can be accurately set and is given as the ratio of resistor R2 to resistor R1. The Duty Cycle for the 555 Oscillator, which is the ratio of the “ON” time divided by the “OFF” time is given by:
555 Oscillator Duty Cycle
The duty cycle has no units as it is a ratio but can be expressed as a percentage ( % ). If both timing resistors, R1 and R2 are equal in value, then the output duty cycle will be 2:1 that is, 66% ON time and 33% OFF time with respect to the period.
555 Oscillator Example No1
An Astable 555 Oscillator is constructed using the following components, R1 = 1kΩ, R2 = 2kΩ and capacitor C = 10uF. Calculate the output frequency from the 555 oscillator and the duty cycle of the output waveform.
t1 – capacitor charge “ON” time is calculated as:
t2 – capacitor discharge “OFF” time is calculated as:
Total periodic time ( T ) is therefore calculated as:
The output frequency, ƒ is therefore given as:
Giving a duty cycle value of:
As the timing capacitor, C charges through resistors R1 and R2 but only discharges through resistorR2 the output duty cycle can be varied between 50 and 100% by changing the value of resistor R2. By decreasing the value of R2 the duty cycle increases towards 100% and by increasing R2 the duty cycle reduces towards 50%. If resistor, R2 is very large relative to resistor R1 the output frequency of the 555 astable circuit will determined by R2 x C only.
The problem with this basic astable 555 oscillator configuration is that the duty cycle, the “mark to-space” ratio will never go below 50% as the presence of resistor R2 prevents this. In other words we cannot make the outputs “ON” time shorter than the “OFF” time, as (R1 + R2)C will always be greater than the value of R1 x C. One way to overcome this problem is to connect a signal bypassing diode in parallel with resistor R2 as shown below.
Improved 555 Oscillator Duty Cycle
By connecting this diode, D1 between the trigger input and the discharge input, the timing capacitor will now charge up directly through resistor R1 only, as resistor R2 is effectively shorted out by the diode. The capacitor discharges as normal through resistor, R2.
An additional diode, D2 can be connected in series with the discharge resistor, R2 if required to ensure that the timing capacitor will only charge up through D1 and not through the parallel path ofR2. This is because during the charging process diode D2 is connected in reverse bias blocking the flow of current through itself.
Now the previous charging time of t1 = 0.693(R1 + R2)C is modified to take account of this new charging circuit and is given as: 0.693(R1 x C). The duty cycle is therefore given as D = R1/(R1 + R2). Then to generate a duty cycle of less than 50%, resistor R1 needs to be less than resistor R2.
Although the previous circuit improves the duty cycle of the output waveform by charging the timing capacitor, C1 through the R1 + D1 combination and then discharging it through the D2 + R2combination, the problem with this circuit arrangement is that the 555 oscillator circuit uses additional components, i.e. two diodes.
We can improve on this idea and produce a fixed square wave output waveform with an exact 50% duty cycle very easily and without the need for any extra diodes by simply moving the position of the charging resistor, R2 to the output ( pin 3 ) as shown.
50% Duty Cycle Astable Oscillator
The 555 oscillator now produces a 50% duty cycle as the timing capacitor, C1 is now charging and discharging through the same resistor, R2 rather than discharging through the timers discharge pin 7 as before. When the output from the 555 oscillator is HIGH, the capacitor charges up through R2and when the output is LOW, it discharges through R2. Resistor R1 is used to ensure that the capacitor charges up fully to the same value as the supply voltage.
However, as the capacitor charges and discharges through the same resistor, the above equation for the output frequency of oscillations has to be modified a little to reflect this circuit change. Then the new equation for the 50% Astable 555 Oscillator is given as:
50% Duty Cycle Frequency Equation
Note that resistor R1 needs to be sufficiently high enough to ensure it does not interfere with the charging of the capacitor to produce the required 50% duty cycle. Also changing the value of the timing capacitor, C1 changes the oscillation frequency of the astable circuit.
555 Oscillator Applications
We said previously that the maximum output to either sink or source the load current via pin 3 is about 200mA and this value is more than enough to drive or switch other logic IC’s, a few LED’s or a small lamp etc and that we would need to use a bipolar transistor or MOSFET to amplify the 555’s output to drive larger current loads such as motor or relays.
But the 555 Oscillator can also be used in a wide range of waveform generator circuits and applications that require very little output current such as in electronic test equipment for producing a whole range of different output test frequencies.
The 555 can also be used to produce very accurate sine, square and pulse waveforms or as LED or lamp flashers and dimmers to simple noise making circuits such as metronomes, tone and sound effects generators and even musical toys for Christmas.
We could very easily build a simple 555 oscillator circuit to flash a few LED’s “ON” and “OFF” similar to the one shown, or to produce a high frequency noise from a loudspeaker. But one very nice and simple to build science project using an astable based 555 oscillator is that of an Electronic Metronome.
Metronomes are devices used to mark time in pieces of music by producing a regular and recurring musical beat or click. A simple electronic metronome can be made using a 555 oscillator as the main timing device and by adjusting the output frequency of the oscillator the tempo or “Beats per Minute” can be set.
555 Electronic Metronome
This simple metronome circuit demonstrates just one simple way of using a 555 oscillator to produce an audible sound or note. It uses a 150kΩ potentiometer to control the full range of output pulses or beats, and as it has a 150kΩ value it can be easily calibrated to give an equivalent percentage value corresponding to the position of the potentiometer. For example, 60 beats per minute equals 142.3kΩ or 95% rotation.
Likewise, 120 beats per minute equals 70.1kΩ or 47% rotation, etc. Additional resistors or trimmer’s can be connected in series with the potentiometer to pre-set the outputs upper and lower limits to predefined values, but these additional components will need to be taken into account when calculating the output frequency or time period.
While the above circuit is a very simple and amusing example of sound generation, it is possible to use the 555 Oscillator as a noise generator/synthesizer or to make musical sounds, tones and alarms by constructing a variable-frequency, variable-mark/space ratio waveform generator.
In this tutorial we have used just a single 555 oscillator circuit to produce a sound but by cascading together two or more 555 oscillator chips, various circuits can be constructed to produce a whole range of musical and sound effects. One such novelty circuit is the police car “Dee-Dah” siren given in the example below.
555 Oscillator Police “Dee-Dah” Siren
The circuit simulates a warble-tone alarm signal that simulates the sound of a police siren. IC1 is connected as a 2Hz non-symmetrical astable multivibrator which is used to frequency modulate IC2via the 10kΩ resistor. The output of IC2 alternates symmetrically between 300Hz and 660Hz taking 0.5 seconds to complete each alternating cycle.
Supposing that you have a multi-core processor, whenever you run a process (program), depending on its requirements, it might be executed using all the available multi-cores (say that it’s a multimedia encoding utility which needs a lot of your CPU cycles). Or, if it doesn’t need a lot of CPU usages and a single core is more than capable of handling it, then still, while executing, it might be switched between the multiple CPU cores by your operating system. The OS does this due to various reasons but mainly for achieving a balance between the system’s stability and the performance. And it’s performed by a lower level software utility (Kernel process) called “Scheduler” which decides how to interact a certain process with the available CPU cores, by using a value called the “CPU Affinity Mask”.
or most users, it’s almost always best for letting the OS handle it. But for the power users, having the ability to make a certain process, to be executed by only using a single CPU core (or a certain number of cores) has a slight benefit concerning the performance.
This is because, in a multi-core CPU environment, all the individual CPUs have a separate cache which is only accessible by that CPU core (the most lowest levels of CPU cache is known as “L1” and other “L2”, “L3” are usually shared between the cores).
CPU Core 1 Says: “Oy, that hurts!” …
So what happens when executing a process by switching it between various CPU cores is that, when switching a process to a new CPU core, the “L1”cache of the new core has to be updated and the previous core’s “L1” cache might needed to be deleted etc. This results in a somewhat unnecessary cache activity that ultimately reduces the performance.
So if we only used a certain number of CPU cores while executing that particular program, then we can avoid unnecessary processor cache activities (it’s like with a HDD, if it’s busy deleting/updating files etc, then it’ll be a bit slow while doing other things) thus improving the performance, a bit.
This can be beneficial, especially while running CPU hungry tasks such as encoding (not be a good idea if the encoder is multi-threaded) or Virtualization for example.
It all sounds good, but …
However, it is a bit more complicated than that, and is quite difficult to say when it will be beneficial or non-beneficial from the user’s point of view. For instance, let’s take the same example mentioned above. If while running that program (let’s called it process ‘A’), assigned to a certain core, it was ‘paused’ due to a request from another process with a higher priority, but shortly after, another core was available so that the ‘paused’ process ‘A’ can be run with a minimal delay, yet, since we have assigned it to be executed using a different core, it won’t get that chance.
So it’ll have to wait till that process with higher priority (on the same core where our process ‘A’ is assigned) is finished running or ‘paused’, and thus decreasing its performance. So …
Anyhow, without boring you any further with all these technical nonsense ;-), in modern GNU/Linux distributions, there’s a simple tool that lets us bypass the OS’s automated task execution functionality and binds a program (process) to a certain number of CPU cores with ease. It’s called “taskset”.
You can use this utility to start a process from scratch or it can even “re-map” an existing process to a given number of CPU cores as well.
I’m using Ubuntu (11.10 Oneiric Ocelot), and since it comes this tool pre-installed, all you gotta do is to open up the Terminal window and use the below commands which should get the job done.
Starting a new process ….
Let’s say that I wanted to use a program called “burnP6” (CPU stressing utility) that should only be run/executed using the first CPU core. Then I’ll use the below command in my Terminal window.
taskset -c 0burnP6
The “-c” argument is what enables changing the “CPU Affinity” thus should be untouched.
The value “0” represents the first CPU Core (“0” is for the first one, “1” indicates the second one, “2” for the third one etc) and the “burnP6” is the name of the program (process) that I wanted to run. So depending on your needs, you’ll have to replace these two values with yours.
Let’s say that I wanted to run the same program using the CPU Core number “2”, then I’ll use the below command.
taskset -c 1burnP6
If I wanted to run it using multiple cores (first and the second cores) then I’ll use it in the below format.
taskset -c 0,1burnP6
Binding an existing process …
As long as you know the “ID” (PID) of the process, as mentioned above, you can even bind an existing process to a certain CPU core (or Cores). For that, I’ll use “taskset” in the below format.
taskset -pc 07022
Note that we’ve added “p” which indicates PID (process ID).
Again, you’ll have to replace both “0” (CPU Core number) and “7022” (ID of the process). And I’m sure you know how to get the ID of a running process. If you don’t, then once the process is running, if you use the Unity desktop, then you can use the Gnome System Monitor and under the “Processes” tab, highlight the process and then look under the “ID” value, which is the PID of that particular process (as shown below).
If you don’t use a desktop environment, then enter the below command in your Terminal window and it should printout a list of all the running processes in your OS and from that list under the “PID” value, you can find a process and its ID as well.
ps -A
How do I know if it’s working ?
Well, if your process is CPU intensive (otherwise it doesn’t make a whole lot of sense to change the CPU Affinity value anyway) and if you use a desktop environment, then the built-in system monitor should be able to show you the CPU load for each individual CPU core, and if a particular Core (or Cores) have a higher CPU usage readings, then you know it’s working (as shown in the first screenshot).
But if you’d still prefer the command-line, then you can use another built insystem monitor called “top” for that as well. Again, after running the process and changing its “Affinity mask”, use the below command in your Terminal.
top
Now when it’s running, press the key “1” of your Keyboard and the output should change and display the load for each individual cores as shown below.
That’s it!.
Again, for most users, this is almost always unnecessary. But if you’re some like a system administrator who wants a certain process to be executed by only using a certain number of CPU cores of your PC (in Ubuntu Linux), then I hope that this was a bit helpful. Enjoy!.