checking the status of an ongoing âsleepâ process from the terminal
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?
sleep-wake
add a comment |Â
up vote
3
down vote
favorite
Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?
sleep-wake
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?
sleep-wake
Is there a way to check how long a running "sleep" process has left to go before it ends within the terminal?
sleep-wake
asked Aug 6 at 18:43
BarryBluejeans
585
585
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.
As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.
So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:
First run this command:
ps xa | grep sleep
This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:
1234 s0123 S+ 0:00.01 sleep 789
Here 789 is the number of seconds that the command is supposed to sleep in total.
Then afterwards run this command:
ps xa -o etime,command -c | grep sleep
It will show you the total time the process has been running:
03:15 sleep
This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.
add a comment |Â
up vote
2
down vote
If your version of ps
supports etimes
(etime
in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:
ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'
Example output:
time remaining for sleep is 94 seconds
Or you can simplify that to only show the number:
ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'
These commands will output more than one line if more than one sleep
process is running.
Note: Neither etime
nor etimes
outputs fractional seconds, but sleep
can accept them as an argument. This will likely affect the accuracy of your calculation.
For MacOS and others without etimes
, you can convert etime
(ddd-hh:mm:ss
) to seconds reversing the calculations done in the source of ps
(in print.c
):
ps xa -o etimes,command | awk '
BEGIN
f = "1 60 3600 86400";
split(f, factors)
/[s]leep/
split($1, parts, "[-:]");
count = length(parts);
for (i = count; i > 0; i--)
e += parts[i] * factors[count + 1 - i]
;
print e;
e = 0
'
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.
As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.
So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:
First run this command:
ps xa | grep sleep
This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:
1234 s0123 S+ 0:00.01 sleep 789
Here 789 is the number of seconds that the command is supposed to sleep in total.
Then afterwards run this command:
ps xa -o etime,command -c | grep sleep
It will show you the total time the process has been running:
03:15 sleep
This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.
add a comment |Â
up vote
4
down vote
accepted
The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.
As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.
So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:
First run this command:
ps xa | grep sleep
This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:
1234 s0123 S+ 0:00.01 sleep 789
Here 789 is the number of seconds that the command is supposed to sleep in total.
Then afterwards run this command:
ps xa -o etime,command -c | grep sleep
It will show you the total time the process has been running:
03:15 sleep
This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.
As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.
So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:
First run this command:
ps xa | grep sleep
This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:
1234 s0123 S+ 0:00.01 sleep 789
Here 789 is the number of seconds that the command is supposed to sleep in total.
Then afterwards run this command:
ps xa -o etime,command -c | grep sleep
It will show you the total time the process has been running:
03:15 sleep
This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.
The sleep command in itself offers no service that allows the monitoring of the remaining sleep time. It is also not displayed anywhere.
As the sleep command operates without issuing a series of system calls for the kernel, you won't be able to use a typical debugging tool such as dtruss either. If you try to use the lldb debugger to attach to the process, you'll find that the sleep command is also interrupted and cannot be continued.
So it is not as such possible to very precisely determine the amount of time left. If you can make do with an imprecise result, do the following:
First run this command:
ps xa | grep sleep
This should show you the sleep command with the number of seconds that it is supposed to sleep in total. For example:
1234 s0123 S+ 0:00.01 sleep 789
Here 789 is the number of seconds that the command is supposed to sleep in total.
Then afterwards run this command:
ps xa -o etime,command -c | grep sleep
It will show you the total time the process has been running:
03:15 sleep
This means that the process has sleep for 3 minutes and 15 seconds = 195 seconds. The remaining sleep time is 789 - 195 = 594 seconds.
answered Aug 6 at 20:05
jksoegaard
11.5k1534
11.5k1534
add a comment |Â
add a comment |Â
up vote
2
down vote
If your version of ps
supports etimes
(etime
in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:
ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'
Example output:
time remaining for sleep is 94 seconds
Or you can simplify that to only show the number:
ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'
These commands will output more than one line if more than one sleep
process is running.
Note: Neither etime
nor etimes
outputs fractional seconds, but sleep
can accept them as an argument. This will likely affect the accuracy of your calculation.
For MacOS and others without etimes
, you can convert etime
(ddd-hh:mm:ss
) to seconds reversing the calculations done in the source of ps
(in print.c
):
ps xa -o etimes,command | awk '
BEGIN
f = "1 60 3600 86400";
split(f, factors)
/[s]leep/
split($1, parts, "[-:]");
count = length(parts);
for (i = count; i > 0; i--)
e += parts[i] * factors[count + 1 - i]
;
print e;
e = 0
'
add a comment |Â
up vote
2
down vote
If your version of ps
supports etimes
(etime
in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:
ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'
Example output:
time remaining for sleep is 94 seconds
Or you can simplify that to only show the number:
ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'
These commands will output more than one line if more than one sleep
process is running.
Note: Neither etime
nor etimes
outputs fractional seconds, but sleep
can accept them as an argument. This will likely affect the accuracy of your calculation.
For MacOS and others without etimes
, you can convert etime
(ddd-hh:mm:ss
) to seconds reversing the calculations done in the source of ps
(in print.c
):
ps xa -o etimes,command | awk '
BEGIN
f = "1 60 3600 86400";
split(f, factors)
/[s]leep/
split($1, parts, "[-:]");
count = length(parts);
for (i = count; i > 0; i--)
e += parts[i] * factors[count + 1 - i]
;
print e;
e = 0
'
add a comment |Â
up vote
2
down vote
up vote
2
down vote
If your version of ps
supports etimes
(etime
in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:
ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'
Example output:
time remaining for sleep is 94 seconds
Or you can simplify that to only show the number:
ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'
These commands will output more than one line if more than one sleep
process is running.
Note: Neither etime
nor etimes
outputs fractional seconds, but sleep
can accept them as an argument. This will likely affect the accuracy of your calculation.
For MacOS and others without etimes
, you can convert etime
(ddd-hh:mm:ss
) to seconds reversing the calculations done in the source of ps
(in print.c
):
ps xa -o etimes,command | awk '
BEGIN
f = "1 60 3600 86400";
split(f, factors)
/[s]leep/
split($1, parts, "[-:]");
count = length(parts);
for (i = count; i > 0; i--)
e += parts[i] * factors[count + 1 - i]
;
print e;
e = 0
'
If your version of ps
supports etimes
(etime
in seconds) (unfortunately not supported on MacOS), you can use this to calculate the remaining time:
ps xa -o etimes,command | awk '/[s]leep/ print "time remaining for", $2, "is", $3 - $1, "seconds"'
Example output:
time remaining for sleep is 94 seconds
Or you can simplify that to only show the number:
ps xa -o etimes,command | awk '/[s]leep/ print $3 - $1'
These commands will output more than one line if more than one sleep
process is running.
Note: Neither etime
nor etimes
outputs fractional seconds, but sleep
can accept them as an argument. This will likely affect the accuracy of your calculation.
For MacOS and others without etimes
, you can convert etime
(ddd-hh:mm:ss
) to seconds reversing the calculations done in the source of ps
(in print.c
):
ps xa -o etimes,command | awk '
BEGIN
f = "1 60 3600 86400";
split(f, factors)
/[s]leep/
split($1, parts, "[-:]");
count = length(parts);
for (i = count; i > 0; i--)
e += parts[i] * factors[count + 1 - i]
;
print e;
e = 0
'
edited Aug 7 at 20:54
answered Aug 6 at 23:30
Dennis Williamson
121115
121115
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f333012%2fchecking-the-status-of-an-ongoing-sleep-process-from-the-terminal%23new-answer', 'question_page');
);
Post as a guest
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
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
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