Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:09:40+00:00 2026-06-18T10:09:40+00:00

I have a dual quad core machine. so, the cpu list for me 0-7.

  • 0

I have a dual quad core machine. so, the cpu list for me 0-7.

I am trying to run the taskset from python

mapping = [2,2,2,2,2]
for i in range(0,len(mapping)):
        cmd = "taskset -c" +  str(mapping[r]) + "python <path>/run-apps.py" + thr[r] + "&"
        os.system(cmd)

and it says:

taskset: invalid option -- '2'
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

But the core 2 is available and I am to run the same thing from commandline.

taskset -c 2 python <path>/run-apps.py lbm &

not a clue what the issue is..

any hints?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:09:41+00:00Added an answer on June 18, 2026 at 10:09 am

    compared to the commandline you posted, you’re missing a couple spaces … e.g.:

    cmd = "taskset -c " +  str(mapping[r]) + " python <path>/run-apps.py " + thr[r] + " &"
    

    In your code, when parsing the “commandline”, taskset is seeing the string -c2 which according to many commandline parsing libraries is the same thing as -c -2 which would explain the error that you’re seeing.

    Sometimes these things are easier to read if you use string interpolation instead:

    cmd = "taskset -c %s python <path>/run-apps.py %s &" % (mapping[r],thr[r])
    

    Or new style .format:

    cmd = "taskset -c {0} python <path>/run-apps.py {1} &".format(mapping[r],thr[r])
    

    And finally, no solution using os.system should go by without at least a mention of the python subprocess module.

    process = subprocess.Popen(['taskset',
                                '-c',
                                str(mapping[r]),
                                'python',
                                '<path>/run-apps.py',
                                str(thr[r]) ] )
    

    It’ll avoid the shell altogether which is slightly more efficient and makes you safer from shell injection types of attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iMac with 4GB of RAM and dual core cpu but when
I have a 64 bit server, 8 GB RAM, dual quad CPU. No resources
On top of a dual quad core physical host, I would like to run
Suppose we have a dual-core machine with a mainstream, modern OS capable to utilize
I have a dual setup development machine with Visual Studio 2003 and 2005. How
I have a dual list and I am wondering what it the best way
I'm still trying to learn jquery so bear with me. I have a dual
I currently have a machine with an Opteron 275 (2.2Ghz), which is a dual
I have a dual core processor and according to the explanation I'm able to
I have been doing some test on my Pentium D (an old dual core

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.