Perl Planning Priority Runnig OS Features

Is it possible that Perl runs Linux with a changed scheduling priority and / or IO without external commands? I am trying to simulate the following:

nice -n19 ionice -c2 -n7 cp largefile largefile2 

Is there any way to do this with File :: Copy, the setpriority function and the CPAN module of Linux :: IO_Prio? Would I just have to lower my $ 0 scheduling priority?

EDIT: If I do the following, will priority and IO be omitted for copy ()? Is there a better way to do this?

 use Linux::IO_Prio qw(:all); use File::Copy; setpriority(0, 0, -20); ionice(IOPRIO_WHO_PROCESS, $$, IOPRIO_CLASS_IDLE, 7); copy("file1","file2") or die "Copy failed: $!"; 
+4
source share
2 answers

Refining Responses to Ezors :

 use BSD::Resource qw(PRIO_PROCESS setpriority); use Linux::IO_Prio qw(IOPRIO_WHO_PROCESS IOPRIO_PRIO_VALUE IOPRIO_CLASS_BE ioprio_set); BEGIN { require autodie::hints; autodie::hints->set_hints_for(\&ioprio_set, { fail => sub { $_[0] == -1 } } ) }; use autodie qw(:all setpriority ioprio_set); setpriority( PRIO_PROCESS, # 1 $$, 19 ); ioprio_set( IOPRIO_WHO_PROCESS, # 1 $$, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 7) # 0x4007 ); 

By the way, you can find library calls and similar things with strace .

+1
source

You are probably best off just changing the priority of the currently running pid as needed. Of course, it is not tolerated, but this in itself is not tolerated. Everything that does such things boils down to making the same library calls as external commands.

 my $pid = $$; `ionice -c2 -p$pid`; `renice +19 $pid`; 
+1
source

Source: https://habr.com/ru/post/1387050/


All Articles