2

I want to have a cron job that will set the priority of some services, however, the parent runs as root and the rest as another user. However, the parent will respawn processes with it's priority ID so the cron job would have to run way more then it should. Is there a way to do this to set priority's?

Example of what I want to set higher:

1 S root     13826     1  0  81   0 -  3289 rt_sig 00:33 ?        00:00:00 nginx: master process /usr/local/sbin/nginx -c /etc/nginx/nginx.conf
5 S root     15474     1  0  75   0 -  3848 -      Apr22 ?        00:01:37 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19511 13826  0  75   0 -  3297 -      13:06 ?        00:00:10 nginx: worker process
5 S nobody   19512 13826  0  78   0 -  3361 -      13:06 ?        00:00:11 nginx: worker process
5 S nobody   19513 13826  0  75   0 -  3681 -      13:06 ?        00:00:09 nginx: worker process
5 S nobody   19514 13826  0  78   0 -  3297 -      13:06 ?        00:00:07 nginx: worker process
5 S root     19521 15474  0  77   0 -  3561 -      13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19522 15474  0  78   0 -  3848 431083 13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19523 15474  0  75   0 -  3952 semtim 13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19524 15474  0  75   0 -  3951 semtim 13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19525 15474  0  75   0 -  3949 semtim 13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19526 15474  0  78   0 -  3947 -      13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL
5 S nobody   19527 15474  0  78   0 -  3949 semtim 13:06 ?        00:00:00 /usr/local/apache/bin/httpd -k start -DSSL

I know there is http://www.rfxn.com/projects/system-priority/ but as far as I know that only does it by UID.

3
  • It is clear that you have a specific question in mind, but I don't quite understand it. Could you reword it a little?
    – thb
    Apr 28, 2012 at 18:22
  • 1
    I don't understand what you want to do, but in Bash, the $PPID variable holds the PID of its the parent process. Apr 28, 2012 at 18:30
  • I just need to be able to change priority on the following services but can't via userID or by PID because they change. I need to be able to grep for user ID(like nobody) then pull mother PID so I can set the priority. Apr 29, 2012 at 5:41

1 Answer 1

4

The question isn't very clear, you can easily find the parent PID though by looking at /proc/18357/stat replacing 18357 with the PID of the current process

the parent PID is the fourth argument in there

2
  • perhaps. extracting the data from this file would be far more efficient than forking off a ps process and extracting the data though
    – James C
    Nov 27, 2012 at 18:05
  • 1
    Note that just looking for the fourth field in /proc/18357/stat won't work if the process command line contains a space. I think getting value from the the PPid: line from /proc/18357/status file is more reliable, like this: grep '^PPid:' "/proc/$$/status" | cut -f 2
    – oliver
    Sep 1, 2017 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.