why aren't operating systems using this overflow flag to stop integer overflows?
The operating system can't just forbid integer overflows, because sometimes it's not a bug but a feature. There is software out there which contains algorithms which actually rely on integer overflow behavior and would break if it would no longer work the way it does.
Users usually do not like it if their old software doesn't work anymore after an operating system update.
what is the usage of this overflow flag then?
The overflow- and carry-flags are relevant whenever you want to implement calculations with numbers which are larger than the register-width of the CPU. If you have a 32 bit CPU but want to do 64 bit arithmetics, then you need to perform multiple operations where the values of the overflow- and carry-flag are important for the subsequent steps. But only software developers who work in assembly actually need to keep that in mind. Any modern high-level programming languages generate the necessary code automatically. And that code relies on those flags, so this is another reason why you can't just forbid integer overflows.
Very few high-level programming languages actually expose information about whether or not integer overflows occurred.
how does the CPU knows whether we used int x or unsigned x in our program?
Because there are different CPU instructions for signed and unsigned integer operations. For example there is MUL
for signed multiplication and IMUL
for unsigned multiplication (with addition and subtraction of binary numbers there is actually no difference between signed and unsigned operations). When you are not writing assembly and use a higher programming language, then the compiler/interpreter is responsible for picking the correct instruction.