How to determine whether a command is running or not from bash
I want to re-run a file php every time it ends...
Then I have created i file SH like this
VAR_1=1;
while [[ $VAR_1 != "2" ]]; do
for filename in *.php; do
if [ -- check if command is NOT running -- ]; then
sleep .5
php $filename
fi
done
done
What kind of IF i must use ?
command-line bash
add a comment |
I want to re-run a file php every time it ends...
Then I have created i file SH like this
VAR_1=1;
while [[ $VAR_1 != "2" ]]; do
for filename in *.php; do
if [ -- check if command is NOT running -- ]; then
sleep .5
php $filename
fi
done
done
What kind of IF i must use ?
command-line bash
What is the output of the php process? Use that to determine when to re-run that file!
– George Udosen
8 hours ago
add a comment |
I want to re-run a file php every time it ends...
Then I have created i file SH like this
VAR_1=1;
while [[ $VAR_1 != "2" ]]; do
for filename in *.php; do
if [ -- check if command is NOT running -- ]; then
sleep .5
php $filename
fi
done
done
What kind of IF i must use ?
command-line bash
I want to re-run a file php every time it ends...
Then I have created i file SH like this
VAR_1=1;
while [[ $VAR_1 != "2" ]]; do
for filename in *.php; do
if [ -- check if command is NOT running -- ]; then
sleep .5
php $filename
fi
done
done
What kind of IF i must use ?
command-line bash
command-line bash
asked 8 hours ago
FireFoxIIFireFoxII
1083
1083
What is the output of the php process? Use that to determine when to re-run that file!
– George Udosen
8 hours ago
add a comment |
What is the output of the php process? Use that to determine when to re-run that file!
– George Udosen
8 hours ago
What is the output of the php process? Use that to determine when to re-run that file!
– George Udosen
8 hours ago
What is the output of the php process? Use that to determine when to re-run that file!
– George Udosen
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
( readlink /proc/*/exe | grep -q '/path/to/the/command' )
Will return 0 if a process is running /path/to/the/command.
However, the canonical way to do this is a bit different:
- On startup, the process checks if some known file (typically
/run/$commandname.pid) exists - If so, it reads the PID in it, and check if said process is still running (for instance, there is a
/proc/$pid/directory) - If yes, it exits
- Otherwise (no PID file, or process no longer running), it writes its own PID in the file and starts.
add a comment |
use pgrep
if ! pgrep -f "php $filename"; then echo "command not running"; fi
However, "I want to re-run a file php every time it ends", so why don't you just do this:
while true; do
php "$filename"
done
Then you don't have to search for it, when it ends it will just run again.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1122525%2fhow-to-determine-whether-a-command-is-running-or-not-from-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
( readlink /proc/*/exe | grep -q '/path/to/the/command' )
Will return 0 if a process is running /path/to/the/command.
However, the canonical way to do this is a bit different:
- On startup, the process checks if some known file (typically
/run/$commandname.pid) exists - If so, it reads the PID in it, and check if said process is still running (for instance, there is a
/proc/$pid/directory) - If yes, it exits
- Otherwise (no PID file, or process no longer running), it writes its own PID in the file and starts.
add a comment |
( readlink /proc/*/exe | grep -q '/path/to/the/command' )
Will return 0 if a process is running /path/to/the/command.
However, the canonical way to do this is a bit different:
- On startup, the process checks if some known file (typically
/run/$commandname.pid) exists - If so, it reads the PID in it, and check if said process is still running (for instance, there is a
/proc/$pid/directory) - If yes, it exits
- Otherwise (no PID file, or process no longer running), it writes its own PID in the file and starts.
add a comment |
( readlink /proc/*/exe | grep -q '/path/to/the/command' )
Will return 0 if a process is running /path/to/the/command.
However, the canonical way to do this is a bit different:
- On startup, the process checks if some known file (typically
/run/$commandname.pid) exists - If so, it reads the PID in it, and check if said process is still running (for instance, there is a
/proc/$pid/directory) - If yes, it exits
- Otherwise (no PID file, or process no longer running), it writes its own PID in the file and starts.
( readlink /proc/*/exe | grep -q '/path/to/the/command' )
Will return 0 if a process is running /path/to/the/command.
However, the canonical way to do this is a bit different:
- On startup, the process checks if some known file (typically
/run/$commandname.pid) exists - If so, it reads the PID in it, and check if said process is still running (for instance, there is a
/proc/$pid/directory) - If yes, it exits
- Otherwise (no PID file, or process no longer running), it writes its own PID in the file and starts.
answered 7 hours ago
xenoidxenoid
1,7531416
1,7531416
add a comment |
add a comment |
use pgrep
if ! pgrep -f "php $filename"; then echo "command not running"; fi
However, "I want to re-run a file php every time it ends", so why don't you just do this:
while true; do
php "$filename"
done
Then you don't have to search for it, when it ends it will just run again.
add a comment |
use pgrep
if ! pgrep -f "php $filename"; then echo "command not running"; fi
However, "I want to re-run a file php every time it ends", so why don't you just do this:
while true; do
php "$filename"
done
Then you don't have to search for it, when it ends it will just run again.
add a comment |
use pgrep
if ! pgrep -f "php $filename"; then echo "command not running"; fi
However, "I want to re-run a file php every time it ends", so why don't you just do this:
while true; do
php "$filename"
done
Then you don't have to search for it, when it ends it will just run again.
use pgrep
if ! pgrep -f "php $filename"; then echo "command not running"; fi
However, "I want to re-run a file php every time it ends", so why don't you just do this:
while true; do
php "$filename"
done
Then you don't have to search for it, when it ends it will just run again.
answered 6 hours ago
glenn jackmanglenn jackman
12.5k2545
12.5k2545
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1122525%2fhow-to-determine-whether-a-command-is-running-or-not-from-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the output of the php process? Use that to determine when to re-run that file!
– George Udosen
8 hours ago