Use flock
for both things: locking a file during the execution of the script B and checking the lock status from the script.
When launching script B:
flock /tmp/lockfile.lck ScriptB.sh
Inside script A, to detect the lock:
flock -n /tmp/lockfile.lck echo "Script B is not running" || echo "Script B is running right now"
The '-n' option makes flock
to "not wait" for the releasing (the default action) of the lock file. Thus, that would be another way of using flock, if waiting is what you desire.