How to check if file is in use? I have c++ application and I need to know if one file is in use by anyone. I'm ok with running any shell command, but I don't want to run lsof command for this purpose, since I think I can't safely assume that lsof will be available on all OS, or can I safely assume that?
You can assume that lsof ships on all macOS and you can also check the existence of that command before you call it, logging a nice friendly error message and or log message as you see fit if you want to code defensively.

You could also ask on a code-focused site what API exist to check for file existence if you want to go into specific C++ code (which would be off topic here), but from your question assuming you can call any command line tool, your overall design is fine to execute in a C++ program on macOS.