CPU Affinity

Discussion in 'Linux, BSD and Other OS's' started by thoonie, Dec 13, 2006.

  1. thoonie

    thoonie hmmm....

    Likes Received:
    0
    Trophy Points:
    16
    First off, how do you list all processes that are running using ssh? And how do you set the affinity of a process to one core of a CPU in Linux (anydistro)?
     
  2. Anti-Trend

    Anti-Trend Nonconformist Geek

    Likes Received:
    118
    Trophy Points:
    63
    Let me explain that SSH, or Secure SHell, is simply a way to securely connect to and get a remote shell on a Linux/UNIX system. Commands "in SSH" are actually relative to what shell you're getting once you SSH; SSH isn't a shell in itself. But, that all said, you can list all process like so:
    Code:
    ps -A
    ...or alternately, if you only wanted to list the processes for one particular user, you could do
    Code:
    ps -u $USER
    ... Where $USER should be the actual username.

    Linux kernel >=2.5 has built-in natural process affinity, which means that it will try and keep a process tied to a particular CPU as much as possible by default. This is very good behavior. However, you can manually bind a process to a particular CPU quite easily (you must own the process or be root):
    Code:
    bind [I]pid cpu_mask[/I]
    ...where pid = the process ID and cpu_mask = the decimal ID of the CPU (e.g. 1, 2, 3 etc). So for an example, if I wanted to bind my UT2004 server (with PID 242424) to the 2nd CPU on my server, I'd do this:
    Code:
    bind 242424 2
     
  3. thoonie

    thoonie hmmm....

    Likes Received:
    0
    Trophy Points:
    16
    your a star ;)
     
  4. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    Thanks AT, I never knew Linux lets you manually bind processes to CPUs.
     

Share This Page