Derived from Dan Moulding's POSIX answer, this should work :
#include
#include
long millis(){
struct timespec _t;
clock_gettime(CLOCK_REALTIME, &_t);
return _t.tv_sec*1000 + lround(_t.tv_nsec/1.0e6);
}
Also as pointed out by David Guyon: compile with -lm