LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 02-20-2010, 04:33 PM   #1
lwi
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:

Code:
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:
Code:
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,

Lwi
 
Old 02-28-2010, 09:54 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
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
lwi
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
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
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.
 
  


Reply

Tags
cpuaffinity



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 08:48 PM.

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