To detect if a matrix is ill-conditioned you can check the condition number defined, for the matrix $A$
as:
$$
k(A) = ||A|| \, ||A^{-1}||
$$
For norm 2 this is equal to the ratio of singular values:
$$
k(A) = \frac{\sigma_{max}(A)}{\sigma_{min}(A)}
$$
Numerically there are also other methods to estimate $k(A)$. For more details see chapter 15 of [1], and [2] where you can find source code for different methods (Hager, from LINPACK, sampling) in different languages.
To threat an ill-conditioned system there are two principal ways:
preconditioning: using this technique you obtain a system mathematically equivalent to the start situation, but with a better condition number. The methods depend on the structure of the matrix that you have, but you can see for example [3] for iterative methods.
regularization: here you obtain an approximation of the starter system, these methods work also for ill-posed problem. Example of techniques in this family are:
For more details and references see for example [4].
[1] Higham, Nicholas J., Accuracy and stability of numerical algorithms., Philadelphia, PA: SIAM. xxx, 680 p. (2002). ZBL1011.65010.
[2] web page Matrix Condition Number Estimation
[3] Saad, Yousef, Iterative methods for sparse linear systems., Philadelphia, PA: SIAM Society for Industrial and Applied Mathematics. xviii, 528 p. (2003). ZBL1031.65046.
[4] REGULARIZATION TECHNIQUESBASED ON KRYLOV SUBSPACE METHODSFOR ILL-POSED LINEAR SYSTEMS