Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Ubuntu This forum is for the discussion of Ubuntu Linux.


  Search this Thread
Old 02-20-2010, 04:33 PM   #1
LQ Newbie
Registered: Feb 2010
Posts: 2

Rep: Reputation: 0
Angry CPU affinity / taskset does not always work.

I have a program for which it seems to be impossible to set cpu affinity from launch with the command taskset -c <cpu list> <command> <arguments>

It seems to work fine with xclock:

vision@ackbar:~$ taskset -c 0,1 xclock -digital &
[1] 15997
vision@ackbar:~$ taskset -pc $!
pid 15997's current affinity list: 0,1
but when I try it with my own program, it launches correctly but the cpu affinity is not set like I want it to.

I can however set it afterwards using it's PID:
vision@ackbar:~$ taskset -c 0,1 ltplayerlua < /dev/null >&/dev/null &
[2] 16170
vision@ackbar:~$ taskset -pc $!
pid 16170's current affinity list: 0
vision@ackbar:~$ taskset -pc 0,1 16170
pid 16170's current affinity list: 0
pid 16170's new affinity list: 0,1
vision@ackbar:~$ taskset -pc 16170
pid 16170's current affinity list: 0,1
.. it works but I find it very annoying that I can't set it right from the start.

any ideas?

thanks in advance,

Old 02-28-2010, 09:54 PM   #2
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
Is ltplayerlua a binary or a script?

Are you attempting to redirect file descriptors for taskset, or for ltplayerlua?
Old 03-01-2010, 11:21 AM   #3
LQ Newbie
Registered: Feb 2010
Posts: 2

Original Poster
Rep: Reputation: 0
it's a binary, and the redirections are meant for ltplayerlua... I'm kinda seeing where you are going with this, but the redirections seem to be working fine, i.e. no output on the terminal.

How would the redirections make taskset not work?
Old 03-01-2010, 12:49 PM   #4
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
I'm not sure how the redirection works in your environment. But, AFAIK, in some
environments, the shell would be doing the redirection for the taskset command
initially, not the ltplayerlua, because you haven't escaped the redirections.

As far as the shell syntax is concerned, taskset is the command. It doesn't know
that ltplayerlua is a command. To the shell, ltplayerlua is just an argument to
the taskset command.

Then, if your environment was set up not to close file descriptors during execution
of a subtask, ltplayerlua could inherit that redirection once it executes. With
some programs, if they are not connected to a tty, they conclude that they are
running in the background, and behave differently. In your environment, if the
redirections do first apply to taskset, since it's then no longer associated with
a tty, maybe it behaves differently.

In my environment, I know of no documentation that says that taskset will behave
differently if it's running in the background. So I know of no specific reason why
it would. But you're doing two things that are similar, you're expecting similar
results, and you're not getting similar results. I often find that looking at the
differences between two similar things, one that works and one that doesn't, allows
me to get the one that wasn't working, to work, without having to explain exactly
why it didn't work in the first place.

You might want to try to find a way to force the redirections to apply only to
ltplayerlua. Or for now, just hard code the use of /dev/null internal to
ltplayerlua just to see if it works that way.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
taskset and affinity masks tethysgods Linux - Software 1 01-16-2010 12:29 PM
Taskset on multicore cpu DinoFly Linux - General 4 10-31-2009 05:03 PM
Using taskset to set process affinity on multi-core/hyperthreading lennyk Linux - Software 0 04-06-2009 09:29 AM
CPU binding - How to modify the CPU affinity mask? Thaidog Linux - General 1 03-15-2008 05:54 PM
Processor affinity and cpu scheduling...? Thaidog Linux - Newbie 5 01-09-2003 07:08 PM > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration