Why these lines of code:
if(my_rank != 0) { sprintf(msg, \"Hello from %d of %d...\", my_rank, comm_sz); if(my_rank == 2) { sleep(2); spri
strlen() does not include the null terminator, hence it will not be sent to the master. Receiving the message from rank 3 will not overwrite the later part of the string, so it is still displayed. You should use strlen(msg) + 1 as send count.
strlen()
strlen(msg) + 1