sudo rm somefile; sudo touch somefile
is safe in most situations.
Most processes open files and then use the acquired file descriptor to access the file contents.
If a process opens somefile, in sh:
Then another process is free to unlink(=remove) somefile and the filedescriptor on which somefile was open by the first process (3 in this case) will continue to refer to the original contents of somefile, which is now a file in limbo.
sudo touch somefile
will create a new, unrelated somefile and all processes that had the old somefile open and now are only using a filedescriptor to refer to it will not be affected because they're refering to a different file -- one that's now in limbo.
If a non-root process attemtpts to refer to somefile by name, they'll get an EPERM error, because the new somefile is root-owned.
If you want to prevent multiple processes under the same user (e.g., root) from corrupting a file, linux has mandatory and advisory file locking.
You can use the
flock command in shell scripts for advisory file locking (see the manpage for more info).