how to kill the process of cron job.
Moderator: General Moderators
how to kill the process of cron job.
if i set up a cron job for a script.. if the next cronjob run after first run, how should i detect that the first cronjob is not finished and avoid the execution of the 2nd run of the cron job.
Your idea go likedjot wrote:-
guess you can handle process ids to do that. anyone?
Since my knowledge of that is limited, I would keep a logfile, where I would write "finished" to, when the first process is over. So next start of the cron you may check whether status is "finished" or "running..."
djot
-
1. Check if the status in the log file is finished.
2. If status = running , then do nothing,
3. if status = finish, Update the status = running,
4. After update status = running, then do whatever needed,
5. After finishing everything. update the status = finish.
Is that what you mean?
Is there any function that can determine the process id of the current running cron job in php or linux commands?
got my idea ... as sa(i)d, I don't know how to handle process ids.
see http://de2.php.net/pcntl
see http://de2.php.net/pcntl
you may use lock files. Lock file is an empty file on which you obtain the lock to prevent concurrent execution. Something like this:
There are other ways as well, e.g. semaphores
Code: Select all
define('LOCKFILE', '/tmp/my.lock');
if(!defined('LOCK_EX')) {
define('LOCK_EX', 2);
}
if(!defined('LOCK_NB')) {
define('LOCK_NB', 4);
}
if(!defined('LOCK_UN')) {
define('LOCK_UN', 3);
}
$fp = fopen(LOCKFILE, 'w');
if( !flock($fp, LOCK_EX|LOCK_NB) ) {
die("Failed to obtain the lock");
}
// your script here
flock($fp, LOCK_UN);
fclose($fp);