hi guys
i had written a shell script Display Information of all the File Systems
i want to find the pid and kill the process after few minutes.how can i obtain the pid and kill it???
sample.sh
df -a >> /tmp/size.log
and my cron to execute every minute every hour every day
* * * * * /tmp/sample.sh
Why are you running the script in the first place, if you want to later find it's pid and kill it? This doesn't appear to be an efficient way of achieving your task. What exactly do you want to achieve?
1 Like
say i am executing my script using cron for every minutes
i need to find the pid of it and kill it at some point in time..
this is my requirement
kill $(ps -C "myscript.sh" -o pid=)
1 Like
i wrote tis code in my script!
can u tell me what does this
pid=
do in the code
-o pid
is a format specifier for the ps command that prints only the PID's of the processes specfied by the -c
switch (in this case "myscript.sh"). But this will print the default column header name "PID" and then list all the pid's below this header. To have a different header name, you could simply say -o pid="MyScriptPIDs"
.
Here, we are not supplying any header name in -o pid=
, which means no header will be printed and so that you could use the output in kill command.
1 Like