Stop/kill a process from the command line after a certain amount of time
The simplest solution would be to use timeout
from the collection of GNU coreutils (probably installed by default on most Linux systems):
timeout 10 ./sopare.py -l
See the manual for this utility for further options (man timeout
). On non-GNU systems, this utility may be installed as gtimeout
if GNU coreutils is installed at all.
Another alternative, if GNU coreutils is not available, is to start the process in the background and wait for 10 seconds before sending it a termination signal:
./sopare.py -l &
sleep 10
kill "$!"
$!
will be the process ID of the most recently started background process, in this case of your Python script.
In case the waiting time is used for other things:
./sopare.py -l & pid=$!
# whatever code here, as long as it doesn't change the pid variable
kill "$pid"
Related videos on Youtube
d4rty
Updated on September 18, 2022Comments
-
d4rty over 1 year
I have a component with the following template (...component.html):
<canvas></canvas>
Furthermore I have in ...component.ts:
export class TestComponent implements AfterViewInit { @ViewChild('canvas') private canvasRef: ElementRef;
How can I now calculate the to the window border as marked in the picture below (see red lines)?
For jQuery users: I'm looking for a way to calculate
$("#desiredCanvasElement").position();
-
enno.void over 6 years
-
d4rty over 6 years@mr.void using jQuery is fine for me. Just don't know how to use the
canvasRef
property together with jQuery -
enno.void over 6 yearsjust do $(canvasRef) , ensure jquery is loaded
-
d4rty over 6 yearsjust
$(canvasRef)
leads to an error,$(this.canvasRef.nativeElement)
works! -
Stephen Boston over 5 yearsDoes this help serverfault.com/questions/205498/…
-
Haxiel over 5 yearsSince you want to end the program after a specified amount of time, you can look at
timeout
: ss64.com/bash/timeout.html
-
-
d4rty over 6 yearsThis doesn't work, since the padding is part of the element itself (as you use it in your fiddle). If you change padding to margin (which is an example for my usecase) your solution doesn't work.
-
Pezetter over 6 yearsFair enough, but the same methodology should work, no?
-
Kusalananda over 5 yearsYou don't start anything in the background. If you did (using
&
), the PID of that process would be available in"$!"
. -
Z E Nir over 5 yearsI thought
"$!"
will return the PID of the invoking script... good to learn new things. Thanks! (btw i didn't try it with python, but my script is working with awhile(1)
C program) Also in your solution, you must consider 10 seconds is a lot of time and maybe$!
value is no longer what you wanted... -
Kusalananda over 5 yearsYou have
$$
which would be the PID of the current script. Is that what you're thinking of?