First, find out the id of the process that is holding the lock file.
sudo lsof /var/lib/dpkg/lock-frontend
The above command will give you the details of the processes using the lock files. Use the process ID to kill this program:
sudo kill -9 PID
Now you can remove the lock and reconfigure dpkg:
sudo rm /var/lib/dpkg/lock-frontend
sudo dpkg --configure -a