Process with rank = sender_rank sends message to itself. MPI_Finalize is never called on execution of the program because it is not received.
for(int i=0;i<size;i++){
if(i!= TO_RANK)
MPI_Send(msg,N,MPI_CHAR,i,msg_tag,MPI_COMM_WORLD);
}
This will resolve the problem.