I am using cron to run a php script every minute and I want to lock it so it won't overlap. So my question is, if I lock the cron job with flock, will lock the process of the cron or of the php-script?
flock wraps the lock around the executing a command and will hold the lock for as long as that command is running.
If this is your cronjob that runs every minute:
* * * * * /usr/bin/flock -n /tmp/fcj.lockfile /usr/local/bin/frequent_cron_job
flock will hold the lock for the duration of
/usr/local/bin/frequent_cron_job. If that batch job takes longer than a minute, cron won't be able to acquire the lock and won't run that batch again and/or multiple instances of frequent_cron_job concurrently, until that lock has been released.