How set the “oom_score_adj” when(before) run target program?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Directly set by echo 1000 >/proc/<pid>/oom_score_adj is unreliable because target program is already running , in this case maybe target program caused OOM before echo 1000 >/proc/<pid>/oom_score_adj







share|improve this question
























    up vote
    1
    down vote

    favorite












    Directly set by echo 1000 >/proc/<pid>/oom_score_adj is unreliable because target program is already running , in this case maybe target program caused OOM before echo 1000 >/proc/<pid>/oom_score_adj







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Directly set by echo 1000 >/proc/<pid>/oom_score_adj is unreliable because target program is already running , in this case maybe target program caused OOM before echo 1000 >/proc/<pid>/oom_score_adj







      share|improve this question












      Directly set by echo 1000 >/proc/<pid>/oom_score_adj is unreliable because target program is already running , in this case maybe target program caused OOM before echo 1000 >/proc/<pid>/oom_score_adj









      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 7 '17 at 8:14









      illiterate

      1259




      1259




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          oom_score_adj is inherited on fork, so you can set its initial value for new children by setting the desired value on the parent process.



          Thus if you’re starting the target from a shell script,



          echo 1000 > /proc/$$/oom_score_adj


          will change the shell’s value to 1000, and any process subsequently forked by the shell will start with oom_score_adj set to 1000.






          share|improve this answer





























            up vote
            0
            down vote













            As an alternative to setting it on the parent process, as in M. Kitt's answer, one can set it on the child process after the fork by running the program in the child process via a chain-loading tool that imposes the setting on itself and then simply chain loads the target program.



            I wrote one such utility for the nosh toolset in 2016, that knows the mechanisms for both Linux operating systems and FreeBSD/TrueOS.


            oom-kill-protect -- 1000 target-program some-arguments


            The -- is there for when someone decides to adapt that to use a negative OOM score. ☺



            Further reading



            • Jonathan de Boyne Pollard (2016). oom-kill-protect. nosh toolset.
              Softwares.

            • Jonathan de Boyne Pollard (2016-01-31). syslogd(8) with OOM Killer protection. FreeBSD Hackers.





            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409416%2fhow-set-the-oom-score-adj-whenbefore-run-target-program%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              oom_score_adj is inherited on fork, so you can set its initial value for new children by setting the desired value on the parent process.



              Thus if you’re starting the target from a shell script,



              echo 1000 > /proc/$$/oom_score_adj


              will change the shell’s value to 1000, and any process subsequently forked by the shell will start with oom_score_adj set to 1000.






              share|improve this answer


























                up vote
                1
                down vote



                accepted










                oom_score_adj is inherited on fork, so you can set its initial value for new children by setting the desired value on the parent process.



                Thus if you’re starting the target from a shell script,



                echo 1000 > /proc/$$/oom_score_adj


                will change the shell’s value to 1000, and any process subsequently forked by the shell will start with oom_score_adj set to 1000.






                share|improve this answer
























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  oom_score_adj is inherited on fork, so you can set its initial value for new children by setting the desired value on the parent process.



                  Thus if you’re starting the target from a shell script,



                  echo 1000 > /proc/$$/oom_score_adj


                  will change the shell’s value to 1000, and any process subsequently forked by the shell will start with oom_score_adj set to 1000.






                  share|improve this answer














                  oom_score_adj is inherited on fork, so you can set its initial value for new children by setting the desired value on the parent process.



                  Thus if you’re starting the target from a shell script,



                  echo 1000 > /proc/$$/oom_score_adj


                  will change the shell’s value to 1000, and any process subsequently forked by the shell will start with oom_score_adj set to 1000.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 7 '17 at 9:50

























                  answered Dec 7 '17 at 9:16









                  Stephen Kitt

                  143k22310374




                  143k22310374






















                      up vote
                      0
                      down vote













                      As an alternative to setting it on the parent process, as in M. Kitt's answer, one can set it on the child process after the fork by running the program in the child process via a chain-loading tool that imposes the setting on itself and then simply chain loads the target program.



                      I wrote one such utility for the nosh toolset in 2016, that knows the mechanisms for both Linux operating systems and FreeBSD/TrueOS.


                      oom-kill-protect -- 1000 target-program some-arguments


                      The -- is there for when someone decides to adapt that to use a negative OOM score. ☺



                      Further reading



                      • Jonathan de Boyne Pollard (2016). oom-kill-protect. nosh toolset.
                        Softwares.

                      • Jonathan de Boyne Pollard (2016-01-31). syslogd(8) with OOM Killer protection. FreeBSD Hackers.





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        As an alternative to setting it on the parent process, as in M. Kitt's answer, one can set it on the child process after the fork by running the program in the child process via a chain-loading tool that imposes the setting on itself and then simply chain loads the target program.



                        I wrote one such utility for the nosh toolset in 2016, that knows the mechanisms for both Linux operating systems and FreeBSD/TrueOS.


                        oom-kill-protect -- 1000 target-program some-arguments


                        The -- is there for when someone decides to adapt that to use a negative OOM score. ☺



                        Further reading



                        • Jonathan de Boyne Pollard (2016). oom-kill-protect. nosh toolset.
                          Softwares.

                        • Jonathan de Boyne Pollard (2016-01-31). syslogd(8) with OOM Killer protection. FreeBSD Hackers.





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          As an alternative to setting it on the parent process, as in M. Kitt's answer, one can set it on the child process after the fork by running the program in the child process via a chain-loading tool that imposes the setting on itself and then simply chain loads the target program.



                          I wrote one such utility for the nosh toolset in 2016, that knows the mechanisms for both Linux operating systems and FreeBSD/TrueOS.


                          oom-kill-protect -- 1000 target-program some-arguments


                          The -- is there for when someone decides to adapt that to use a negative OOM score. ☺



                          Further reading



                          • Jonathan de Boyne Pollard (2016). oom-kill-protect. nosh toolset.
                            Softwares.

                          • Jonathan de Boyne Pollard (2016-01-31). syslogd(8) with OOM Killer protection. FreeBSD Hackers.





                          share|improve this answer












                          As an alternative to setting it on the parent process, as in M. Kitt's answer, one can set it on the child process after the fork by running the program in the child process via a chain-loading tool that imposes the setting on itself and then simply chain loads the target program.



                          I wrote one such utility for the nosh toolset in 2016, that knows the mechanisms for both Linux operating systems and FreeBSD/TrueOS.


                          oom-kill-protect -- 1000 target-program some-arguments


                          The -- is there for when someone decides to adapt that to use a negative OOM score. ☺



                          Further reading



                          • Jonathan de Boyne Pollard (2016). oom-kill-protect. nosh toolset.
                            Softwares.

                          • Jonathan de Boyne Pollard (2016-01-31). syslogd(8) with OOM Killer protection. FreeBSD Hackers.






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 7 '17 at 11:48









                          JdeBP

                          28.7k459134




                          28.7k459134



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409416%2fhow-set-the-oom-score-adj-whenbefore-run-target-program%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?