How do I get the PID of my main process (and not one of its workers)?

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











up vote
2
down vote

favorite












I'm using CentOS 7. I'm trying to write a script to start and stop a puma process but I can't figure out how to get the "master" PID, if taht is even the right term. In the below command



[rails@server myproject_production]$ ps aux | grep puma
rails 15767 0.0 1.2 437904 13612 ? Sl 17:20 0:00 puma 3.11.4 (tcp://0.0.0.0:3000,unix:///home/rails/myproject_production/shared/sockets/puma.sock) [myproject_production]
rails 15779 0.6 7.6 1061248 80688 ? Sl 17:20 0:05 puma: cluster worker 1: 15767 [myproject_production]
rails 15781 0.6 7.7 1061248 80876 ? Sl 17:20 0:05 puma: cluster worker 2: 15767 [myproject_production]
rails 15785 0.6 7.4 1061964 78488 ? Sl 17:20 0:05 puma: cluster worker 3: 15767 [myproject_production]
rails 15880 0.7 7.4 1059612 78592 ? Sl 17:22 0:05 puma: cluster worker 0: 15767 [myproject_production]
rails 17106 0.0 0.1 112612 1064 pts/0 S+ 17:33 0:00 grep --color=auto puma


The master PID is "15767". If I kill that all the other puma processes will die. How do I write a command to get taht into a script variable?







share|improve this question



















  • I naively assume you can grep for more text from that line of ps, why can't you?
    – ajeh
    May 9 at 21:53














up vote
2
down vote

favorite












I'm using CentOS 7. I'm trying to write a script to start and stop a puma process but I can't figure out how to get the "master" PID, if taht is even the right term. In the below command



[rails@server myproject_production]$ ps aux | grep puma
rails 15767 0.0 1.2 437904 13612 ? Sl 17:20 0:00 puma 3.11.4 (tcp://0.0.0.0:3000,unix:///home/rails/myproject_production/shared/sockets/puma.sock) [myproject_production]
rails 15779 0.6 7.6 1061248 80688 ? Sl 17:20 0:05 puma: cluster worker 1: 15767 [myproject_production]
rails 15781 0.6 7.7 1061248 80876 ? Sl 17:20 0:05 puma: cluster worker 2: 15767 [myproject_production]
rails 15785 0.6 7.4 1061964 78488 ? Sl 17:20 0:05 puma: cluster worker 3: 15767 [myproject_production]
rails 15880 0.7 7.4 1059612 78592 ? Sl 17:22 0:05 puma: cluster worker 0: 15767 [myproject_production]
rails 17106 0.0 0.1 112612 1064 pts/0 S+ 17:33 0:00 grep --color=auto puma


The master PID is "15767". If I kill that all the other puma processes will die. How do I write a command to get taht into a script variable?







share|improve this question



















  • I naively assume you can grep for more text from that line of ps, why can't you?
    – ajeh
    May 9 at 21:53












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm using CentOS 7. I'm trying to write a script to start and stop a puma process but I can't figure out how to get the "master" PID, if taht is even the right term. In the below command



[rails@server myproject_production]$ ps aux | grep puma
rails 15767 0.0 1.2 437904 13612 ? Sl 17:20 0:00 puma 3.11.4 (tcp://0.0.0.0:3000,unix:///home/rails/myproject_production/shared/sockets/puma.sock) [myproject_production]
rails 15779 0.6 7.6 1061248 80688 ? Sl 17:20 0:05 puma: cluster worker 1: 15767 [myproject_production]
rails 15781 0.6 7.7 1061248 80876 ? Sl 17:20 0:05 puma: cluster worker 2: 15767 [myproject_production]
rails 15785 0.6 7.4 1061964 78488 ? Sl 17:20 0:05 puma: cluster worker 3: 15767 [myproject_production]
rails 15880 0.7 7.4 1059612 78592 ? Sl 17:22 0:05 puma: cluster worker 0: 15767 [myproject_production]
rails 17106 0.0 0.1 112612 1064 pts/0 S+ 17:33 0:00 grep --color=auto puma


The master PID is "15767". If I kill that all the other puma processes will die. How do I write a command to get taht into a script variable?







share|improve this question











I'm using CentOS 7. I'm trying to write a script to start and stop a puma process but I can't figure out how to get the "master" PID, if taht is even the right term. In the below command



[rails@server myproject_production]$ ps aux | grep puma
rails 15767 0.0 1.2 437904 13612 ? Sl 17:20 0:00 puma 3.11.4 (tcp://0.0.0.0:3000,unix:///home/rails/myproject_production/shared/sockets/puma.sock) [myproject_production]
rails 15779 0.6 7.6 1061248 80688 ? Sl 17:20 0:05 puma: cluster worker 1: 15767 [myproject_production]
rails 15781 0.6 7.7 1061248 80876 ? Sl 17:20 0:05 puma: cluster worker 2: 15767 [myproject_production]
rails 15785 0.6 7.4 1061964 78488 ? Sl 17:20 0:05 puma: cluster worker 3: 15767 [myproject_production]
rails 15880 0.7 7.4 1059612 78592 ? Sl 17:22 0:05 puma: cluster worker 0: 15767 [myproject_production]
rails 17106 0.0 0.1 112612 1064 pts/0 S+ 17:33 0:00 grep --color=auto puma


The master PID is "15767". If I kill that all the other puma processes will die. How do I write a command to get taht into a script variable?









share|improve this question










share|improve this question




share|improve this question









asked May 9 at 21:40









Dave

363827




363827











  • I naively assume you can grep for more text from that line of ps, why can't you?
    – ajeh
    May 9 at 21:53
















  • I naively assume you can grep for more text from that line of ps, why can't you?
    – ajeh
    May 9 at 21:53















I naively assume you can grep for more text from that line of ps, why can't you?
– ajeh
May 9 at 21:53




I naively assume you can grep for more text from that line of ps, why can't you?
– ajeh
May 9 at 21:53










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










Use pgrep instead of filtering the output from ps. I think in your case, pgrep -f '^([^ ]*/)?puma ' will match the right process, but experiment a bit to make sure that you're getting what you want and no more.



Once you're satisfied that pgrep is finding the process you want to kill, replace pgrep by pkill.






share|improve this answer





















  • Great solution. Thanks!
    – Dave
    May 9 at 22:52










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%2f442872%2fhow-do-i-get-the-pid-of-my-main-process-and-not-one-of-its-workers%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










Use pgrep instead of filtering the output from ps. I think in your case, pgrep -f '^([^ ]*/)?puma ' will match the right process, but experiment a bit to make sure that you're getting what you want and no more.



Once you're satisfied that pgrep is finding the process you want to kill, replace pgrep by pkill.






share|improve this answer





















  • Great solution. Thanks!
    – Dave
    May 9 at 22:52














up vote
4
down vote



accepted










Use pgrep instead of filtering the output from ps. I think in your case, pgrep -f '^([^ ]*/)?puma ' will match the right process, but experiment a bit to make sure that you're getting what you want and no more.



Once you're satisfied that pgrep is finding the process you want to kill, replace pgrep by pkill.






share|improve this answer





















  • Great solution. Thanks!
    – Dave
    May 9 at 22:52












up vote
4
down vote



accepted







up vote
4
down vote



accepted






Use pgrep instead of filtering the output from ps. I think in your case, pgrep -f '^([^ ]*/)?puma ' will match the right process, but experiment a bit to make sure that you're getting what you want and no more.



Once you're satisfied that pgrep is finding the process you want to kill, replace pgrep by pkill.






share|improve this answer













Use pgrep instead of filtering the output from ps. I think in your case, pgrep -f '^([^ ]*/)?puma ' will match the right process, but experiment a bit to make sure that you're getting what you want and no more.



Once you're satisfied that pgrep is finding the process you want to kill, replace pgrep by pkill.







share|improve this answer













share|improve this answer



share|improve this answer











answered May 9 at 22:04









Gilles

503k1189951522




503k1189951522











  • Great solution. Thanks!
    – Dave
    May 9 at 22:52
















  • Great solution. Thanks!
    – Dave
    May 9 at 22:52















Great solution. Thanks!
– Dave
May 9 at 22:52




Great solution. Thanks!
– Dave
May 9 at 22:52












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442872%2fhow-do-i-get-the-pid-of-my-main-process-and-not-one-of-its-workers%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)