• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

taskset Command Examples in Linux

by Deepika

taskset is a Linux command-line utility that allows you to get or set the CPU affinity of a process or start a new process with a defined CPU affinity. The CPU affinity of a process determines which CPU cores are allowed to execute the process’s threads.

By default, a process can run on any CPU core that is available at the time of execution. However, setting CPU affinity can help you optimize the performance of your system. For example, if you have a multi-core processor and you want to dedicate a particular core to a specific process, you can use taskset to do this.

taskset Command Examples

1. Get a running process’ CPU affinity by PID:

# taskset --pid --cpu-list pid

2. Set a running process’ CPU affinity by PID:

# taskset --pid --cpu-list cpu_id pid

3. Start a new process with affinity for a single CPU:

# taskset --cpu-list cpu_id command

4. Start a new process with affinity for multiple non-sequential CPUs:

# taskset --cpu-list cpu_id_1,cpu_id_2,cpu_id_3

5. Start a new process with affinity for CPUs 1 through 4:

# taskset --cpu-list cpu_id_1-cpu_id_4

Summary

In summary, taskset is a useful tool for managing the CPU affinity of processes on a Linux system. It can help you optimize the performance of your system by dedicating specific CPU cores to specific processes. More information about the command can be found in the manual page by typing “man taskset” in the terminal.

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Limit/throttle rsync transfer speed in Linux
  2. abduco – Terminal session manager (Command Examples)
  3. How to extend an LVM swap partition in Linux
  4. bzfgrep: Find any fixed strings separated by new lines in bzip2 compressed files using fgrep
  5. ss: command not found
  6. einfo Command Examples in Linux
  7. column: Format standard input or a file into multiple columns
  8. CentOS / RHEL 5 : dm-multipath file /etc/sysconfig/mkinitrd/multipath explained
  9. fstrim Command Examples in Linux
  10. rusnapshot Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright