How can I check if a process is running a shell script?

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












Given a process pid, how can I



  • check if the process is running a shell script?


  • if yes, how can I get the child process(es) which the script is running? by pgrep -P <pid>?


Thanks.







share|improve this question





















  • See this stackoverflow.com/questions/38275921/…
    – Ujjwal Singh
    Jul 28 at 1:31










  • Thanks. Mine is a bit different: given a pid.
    – Tim
    Jul 28 at 1:35










  • stackoverflow.com/q/3043978/10008752
    – Ujjwal Singh
    Jul 28 at 1:38










  • Thanks. How do you use them to answer my question?
    – Tim
    Jul 28 at 1:47

















up vote
0
down vote

favorite












Given a process pid, how can I



  • check if the process is running a shell script?


  • if yes, how can I get the child process(es) which the script is running? by pgrep -P <pid>?


Thanks.







share|improve this question





















  • See this stackoverflow.com/questions/38275921/…
    – Ujjwal Singh
    Jul 28 at 1:31










  • Thanks. Mine is a bit different: given a pid.
    – Tim
    Jul 28 at 1:35










  • stackoverflow.com/q/3043978/10008752
    – Ujjwal Singh
    Jul 28 at 1:38










  • Thanks. How do you use them to answer my question?
    – Tim
    Jul 28 at 1:47













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Given a process pid, how can I



  • check if the process is running a shell script?


  • if yes, how can I get the child process(es) which the script is running? by pgrep -P <pid>?


Thanks.







share|improve this question













Given a process pid, how can I



  • check if the process is running a shell script?


  • if yes, how can I get the child process(es) which the script is running? by pgrep -P <pid>?


Thanks.









share|improve this question












share|improve this question




share|improve this question








edited Jul 28 at 1:35
























asked Jul 28 at 1:25









Tim

22.5k61222398




22.5k61222398











  • See this stackoverflow.com/questions/38275921/…
    – Ujjwal Singh
    Jul 28 at 1:31










  • Thanks. Mine is a bit different: given a pid.
    – Tim
    Jul 28 at 1:35










  • stackoverflow.com/q/3043978/10008752
    – Ujjwal Singh
    Jul 28 at 1:38










  • Thanks. How do you use them to answer my question?
    – Tim
    Jul 28 at 1:47

















  • See this stackoverflow.com/questions/38275921/…
    – Ujjwal Singh
    Jul 28 at 1:31










  • Thanks. Mine is a bit different: given a pid.
    – Tim
    Jul 28 at 1:35










  • stackoverflow.com/q/3043978/10008752
    – Ujjwal Singh
    Jul 28 at 1:38










  • Thanks. How do you use them to answer my question?
    – Tim
    Jul 28 at 1:47
















See this stackoverflow.com/questions/38275921/…
– Ujjwal Singh
Jul 28 at 1:31




See this stackoverflow.com/questions/38275921/…
– Ujjwal Singh
Jul 28 at 1:31












Thanks. Mine is a bit different: given a pid.
– Tim
Jul 28 at 1:35




Thanks. Mine is a bit different: given a pid.
– Tim
Jul 28 at 1:35












stackoverflow.com/q/3043978/10008752
– Ujjwal Singh
Jul 28 at 1:38




stackoverflow.com/q/3043978/10008752
– Ujjwal Singh
Jul 28 at 1:38












Thanks. How do you use them to answer my question?
– Tim
Jul 28 at 1:47





Thanks. How do you use them to answer my question?
– Tim
Jul 28 at 1:47











1 Answer
1






active

oldest

votes

















up vote
0
down vote













When you execute a shell script, it will launch a process known as a subshell. As a child process of the main shell, a subshell executes a list of commands in a shell script as a batch (so-called "batch processing").



In some cases, you may want to know the process ID (PID) of the subshell where your shell script is running.



In bash, the PID of a shell script's subshell process is stored in a special variable called '$$'. This variable is read-only, and you cannot modify it in a shell script. For example:



$ cat xyz.sh
#!/bin/bash
echo "PID of this script: $$"


Which gives the following output



PID of this script: XXXX


bash shell exports several other read-only variables. For example, PPID stores the process ID of the subshell's parent process (i.e., main shell). UID stores the user ID of the current user who is executing the script. Like this(only example)



#!/bin/bash
echo "PID of this script: $$"
echo "PPID of this script: $PPID"
echo "UID of this script: $


Which gives the output



PID of this script: XXXX 
PPID of this script: XXXX
UID of this script: XXXX





share|improve this answer





















  • This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
    – JdeBP
    Jul 28 at 10:55










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%2f458975%2fhow-can-i-check-if-a-process-is-running-a-shell-script%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
0
down vote













When you execute a shell script, it will launch a process known as a subshell. As a child process of the main shell, a subshell executes a list of commands in a shell script as a batch (so-called "batch processing").



In some cases, you may want to know the process ID (PID) of the subshell where your shell script is running.



In bash, the PID of a shell script's subshell process is stored in a special variable called '$$'. This variable is read-only, and you cannot modify it in a shell script. For example:



$ cat xyz.sh
#!/bin/bash
echo "PID of this script: $$"


Which gives the following output



PID of this script: XXXX


bash shell exports several other read-only variables. For example, PPID stores the process ID of the subshell's parent process (i.e., main shell). UID stores the user ID of the current user who is executing the script. Like this(only example)



#!/bin/bash
echo "PID of this script: $$"
echo "PPID of this script: $PPID"
echo "UID of this script: $


Which gives the output



PID of this script: XXXX 
PPID of this script: XXXX
UID of this script: XXXX





share|improve this answer





















  • This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
    – JdeBP
    Jul 28 at 10:55














up vote
0
down vote













When you execute a shell script, it will launch a process known as a subshell. As a child process of the main shell, a subshell executes a list of commands in a shell script as a batch (so-called "batch processing").



In some cases, you may want to know the process ID (PID) of the subshell where your shell script is running.



In bash, the PID of a shell script's subshell process is stored in a special variable called '$$'. This variable is read-only, and you cannot modify it in a shell script. For example:



$ cat xyz.sh
#!/bin/bash
echo "PID of this script: $$"


Which gives the following output



PID of this script: XXXX


bash shell exports several other read-only variables. For example, PPID stores the process ID of the subshell's parent process (i.e., main shell). UID stores the user ID of the current user who is executing the script. Like this(only example)



#!/bin/bash
echo "PID of this script: $$"
echo "PPID of this script: $PPID"
echo "UID of this script: $


Which gives the output



PID of this script: XXXX 
PPID of this script: XXXX
UID of this script: XXXX





share|improve this answer





















  • This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
    – JdeBP
    Jul 28 at 10:55












up vote
0
down vote










up vote
0
down vote









When you execute a shell script, it will launch a process known as a subshell. As a child process of the main shell, a subshell executes a list of commands in a shell script as a batch (so-called "batch processing").



In some cases, you may want to know the process ID (PID) of the subshell where your shell script is running.



In bash, the PID of a shell script's subshell process is stored in a special variable called '$$'. This variable is read-only, and you cannot modify it in a shell script. For example:



$ cat xyz.sh
#!/bin/bash
echo "PID of this script: $$"


Which gives the following output



PID of this script: XXXX


bash shell exports several other read-only variables. For example, PPID stores the process ID of the subshell's parent process (i.e., main shell). UID stores the user ID of the current user who is executing the script. Like this(only example)



#!/bin/bash
echo "PID of this script: $$"
echo "PPID of this script: $PPID"
echo "UID of this script: $


Which gives the output



PID of this script: XXXX 
PPID of this script: XXXX
UID of this script: XXXX





share|improve this answer













When you execute a shell script, it will launch a process known as a subshell. As a child process of the main shell, a subshell executes a list of commands in a shell script as a batch (so-called "batch processing").



In some cases, you may want to know the process ID (PID) of the subshell where your shell script is running.



In bash, the PID of a shell script's subshell process is stored in a special variable called '$$'. This variable is read-only, and you cannot modify it in a shell script. For example:



$ cat xyz.sh
#!/bin/bash
echo "PID of this script: $$"


Which gives the following output



PID of this script: XXXX


bash shell exports several other read-only variables. For example, PPID stores the process ID of the subshell's parent process (i.e., main shell). UID stores the user ID of the current user who is executing the script. Like this(only example)



#!/bin/bash
echo "PID of this script: $$"
echo "PPID of this script: $PPID"
echo "UID of this script: $


Which gives the output



PID of this script: XXXX 
PPID of this script: XXXX
UID of this script: XXXX






share|improve this answer













share|improve this answer



share|improve this answer











answered Jul 28 at 2:13









Ujjwal Singh

6112




6112











  • This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
    – JdeBP
    Jul 28 at 10:55
















  • This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
    – JdeBP
    Jul 28 at 10:55















This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
– JdeBP
Jul 28 at 10:55




This is not answering the question posed, as the questioner pointed out in question comments. This is starting from having a shell script and finding its process ID. The question posed is starting from having a process ID and finding a shell script, if any. Note the first four words of the body of the question.
– JdeBP
Jul 28 at 10:55












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f458975%2fhow-can-i-check-if-a-process-is-running-a-shell-script%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?