0

I am using taskset according to linux manual page in order to run a very processing intense task only on specific cores.

The taskset is encapsulated in a loop. Each time a new target directory is selected and the task is beeing run. Running the process multiple times in parallel may lead to fatal results.

The pseudo code is as follows:

#!/bin/bash
while :
do
  target_dir=$(select_dir) # select new directory to process
  sudo taskset -c 4,5,6,7,8,9,10,11 ./processing_intense_task --dir $target_dir
done

I have found nothing in the documentation if taskset actually waits for the process to finish.
If it does not wait, how do I wait for the task completion before starting a new instance of processing_intense_task?

julian bechtold
  • 1,875
  • 2
  • 19
  • 49
  • Why would you ever assume it does not wait? – KamilCuk Nov 11 '21 at 09:56
  • `echo -e '#!/bin/bash\nwhile true; do echo sleep a bit; sleep 1; done' > /tmp/test.sh && chmod u+x /tmp/test.sh && taskset -c 0 /tmp/test.sh` <= Does this return right after the last command or do you have to hit Ctrl-C to stop it? – Zeitounator Nov 11 '21 at 09:57
  • @KamilCuk because there is no information regarding it except that taskset will set the according process affinity. I could not find any documentation or relating questions on stack/google – julian bechtold Nov 11 '21 at 10:00

1 Answers1

1

the documentation if taskset actually waits for the process to finish.

Taskset executes exec, so it becomes the command. https://github.com/util-linux/util-linux/blob/master/schedutils/taskset.c#L246

This is the same as do other similar commands, like nice ionice.

If it does not wait,

Well, technically taskset doesn't wait, it becomes the command itself.

how do I wait for the task completion before starting a new instance of processing_intense_task?

You just wait for taskset process to finish, as it's the same process as the command. I.e. do nothing.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111