3

Could anyone tell me what would occur if I ran

taskset -c 7 ./fred.x

but then inside fred.x a thread is calling sched_setaffinity to bind to core 6?

Would that thread get ANY cpu time ever, or will it remain idle indefinitely?

Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
Derf Skren
  • 479
  • 2
  • 22
  • I swear I should write a script that picks up new posts and changes or reformats random selections. I mean, 3 minutes is hardly a fast turnaround. It's like people aren't even watching. – Derf Skren Jan 12 '15 at 05:05

1 Answers1

3

taskset itself calls sched_setaffinity() and then execve to run your command. So this question boils down to "What happens if I call sched_setaffinity() twice in the same thread?" And the answer is, the second call overrides the first.

So in your specific example, the thread which calls sched_setaffinity() will indeed be bound to core 6, and it will be runnable.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Thanks for the prompt reply. It's my understanding that taskset affects the process and sched_setaffinity affects threads. As long as you're assuring me that having two non-overlapping core affinities for these two things can't happen, you get the points! – Derf Skren Jan 12 '15 at 05:24
  • 2
    `taskset` just calls `sched_setaffinity()` for you. It "affects the process" because when your program starts it has exactly one thread. What you do in your program afterward is none of `taskset`'s concern, nor can it be, because once `taskset` calls `execve`, the `taskset` code is no longer running--your process is. – John Zwinck Jan 12 '15 at 05:27