With the establishment of the Chinese space station, a series of space science missions will be conducted in its vicinity. One of the extended tasks for the in-orbit service of space station is the formation flying of small satellites centered around the space station. Satellite formations can perform simultaneous three-dimensional observations of the space station, generating three-dimensional images and monitoring and assessing the status of critical components of the space station. The real-time and accurate relative position measurement is one of the key issues in formation flying. It is a fundamental prerequisite for maintaining and reconfiguring formation configurations, collision avoidance and safety assurance. GNSS-based relative positioning is a low-cost and high-precision measurement method, which is not constrained by light, weather, or relative attitude of satellites. This study introduces a novel approach to determine the relative position of satellites based on single-epoch Global Navigation Satellite System (GNSS) carrier phase difference measurements. Unlike traditional methods, the proposed technique eliminates the need for precise ephemeris and clock bias files and does not require historical observation data. The algorithm avoids the complexity associated with full cycle ambiguity jumps, facilitating real-time, high-precision calculations of relative position baseline vectors. Special attention is given to the influence of Geostationary Earth Orbit (GEO) satellites in the BeiDou Navigation Satellite System (BDS), and measures are taken to mitigate their impact on measurement accuracy by adjusting their observation weights. Our newly developed GNSS-based real-time measurement module, designed for high-quality GNSS signal reception and data communication, was tested on terrestrial and simulated low-orbit platforms. Remarkably, over baselines ranging from 10 m to 9.3 km, while traditional pseudorange differential measurements showed errors up to 1.5571 m, our proposed method consistently held errors under 5 cm and ensured computational speeds within 0.1 s per epoch. High-dynamic zero-baseline tests further validated its potential, with errors less than 1 cm. The innovations encapsulated in this work, resonating with the evolving trends of miniaturized and scalable satellites, present a cost-efficient and real-time solution for inter-satellite relative position measurement. This promises a new horizon in satellite formation technology, with future endeavors focusing on on-orbit experiments.