taskset命令:多核执行任务

taskset提供的参数:

$ taskset 
taskset (util-linux-ng 2.17.2)
usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]]
set or get the affinity of a process

  -p, --pid                  operate on existing given pid
  -c, --cpu-list             display and specify cpus in list format
  -h, --help                 display this help
  -V, --version              output version information

The default behavior is to run a new command:
  taskset 03 sshd -b 1024
You can retrieve the mask of an existing task:
  taskset -p 700
Or set it:
  taskset -p 03 700
List format uses a comma-separated list instead of a mask:
  taskset -pc 0,3,7-11 700
Ranges in list format can take a stride argument:
  e.g. 0-31:2 is equivalent to mask 0x55555555
$
      命令使用示例一:

#!/bin/bash
if [ $# -ne 1 ] ; then
  echo "Usage: CORE_NUM"
  exit 1
fi
while [ 1 ]
  k=0
  #ulimit -n 10240
  #ulimit -c unlimited
  do
    j=1
    while [ $j -le  21  ]
    do
      i=11
      while [ $i -le 211 ]
      do
        cpu_no=$[ $k % $1 ]
        taskset -c $cpu_no ./test 101.1.1.254  1$k 101.1.$j.$(($i+1)) &
        i=$(($i+1))
        k=$(($k+1))
        taskset -c $cpu_no sleep 1
      done
      j=$(($j+1))
    done
    taskset -c $cpu_no sleep 30000000
  done
      命令使用示例二:
sh-3.1# ps -ef | grep syslog
root      5849     1  0 09:50 ?        00:00:00 /sbin/syslog-ng -p /var/run/syslog-ng.pid --cfgfile /opt/services/conf/syslog_conf.conf
root     14986 14829  0 10:14 pts/1    00:00:00 grep syslog
sh-3.1# taskset -pc 3 5849
pid 5849's current affinity list: 0-3
pid 5849's new affinity list: 3
sh-3.1# 
sh-3.1#htop
  1  [#########***********                                                            22.7%]     Tasks: 246 total, 1 running
  2  [#**                                                                              1.8%]     Load average: 0.10 0.12 0.20 
  3  [#                                                                                0.6%]     Uptime: 01:16:08
  4  [                                                                                 0.0%]
  Mem[||||||||||||||#**************                                              323/1995MB]
  Swp[                                                                                0/0MB]

  PID CPU USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                      
15214   1 root      20   0  5064  1352  1032 R  7.9  0.1  0:01.85 htop                                                                                                                         
 9605   1 root      20   0 12216  1120   940 S  1.2  0.1  0:33.85 /opt/bin/igmp_snoop
14806   1 root      20   0  3276   868   732 S  0.0  0.1  0:00.04 in.telnetd: 192.168.70.13
    1   1 root      20   0  3192   732   620 S  0.0  0.1  0:13.67 init [2]    
 1000   1 root      16  -4  4480   544   368 S  0.0  0.0  0:01.17 udevd --daemon
 5849   4 root      20   0  5040  1004   748 S  0.0  0.1  0:00.12 /sbin/syslog-ng -p /var/run/syslog-ng.pid --cfgfile /opt/services/conf/syslog_conf.conf
 9349   3 root      20   0  4868   832   664 S  0.0  0.1  0:00.02 /usr/sbin/cron
 9377   1 messageb  20   0  8576  2088   880 S  0.0  0.2  0:19.89 /opt/bin/dbus-daemon --system
sh-3.1# F2Setup F3SearchF4InvertF5Tree  F6SortByF7Nice -F8Nice +F9Kill  F10Quit   



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值