Linux 使用shell获取父PID?
我希望有一个cron作业来设置某些服务的优先级,但是,父服务作为root运行,其余的作为另一个用户运行。但是,父进程将使用其优先级ID重新启动进程,因此cron作业必须以超出其应有的方式运行。有没有办法设置优先级 我想设置得更高的示例:Linux 使用shell获取父PID?,linux,shell,process,Linux,Shell,Process,我希望有一个cron作业来设置某些服务的优先级,但是,父服务作为root运行,其余的作为另一个用户运行。但是,父进程将使用其优先级ID重新启动进程,因此cron作业必须以超出其应有的方式运行。有没有办法设置优先级 我想设置得更高的示例: 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/ngin
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
我知道有,但据我所知,它只能通过UID来实现。问题不是很清楚,但是通过查看
/proc/18357/stat
将18357替换为当前进程的PID,您可以很容易地找到父PID
父PID是其中的第四个参数很明显,您心里有一个特定的问题,但我不太明白。你能稍微改写一下吗?我不明白你想做什么,但是在Bash中,$PPID变量保存其父进程的PID。我只需要能够更改以下服务的优先级,但不能通过userID或PID,因为它们会更改。我需要能够grep的用户ID(像没有人),然后拉母PID,这样我就可以设置优先级。也许。从该文件中提取数据要比分叉ps进程并提取数据有效得多。注意,如果进程命令行包含空格,则仅在
/proc/18357/stat
中查找第四个字段将不起作用。我认为从/proc/18357/status
文件的PPid:
行中获取值更可靠,例如:grep'^PPid:“/proc/$$/status”| cut-f2