Service pistol

A service pistol is any handgun or sidearm issued to military personnel or law enforcement officers. It is also known as a personal weapon or ordnance weapon. 
Typically service pistols are revolvers or semi-automatic pistols issued to officers, non-commissioned officers, and rear-echelon support personnel for self defense, though service pistols may also be issued to special forces as a backup for their primary weapons. Pistols are not typically issued to front-line infantry.
Before firearms were commonplace, officers and often NCOs typically carried swords instead.
History.
Prior to the introduction of cartridge-loading firearms, there was little standardization with regards to the handguns carried by military personnel, although it had been important for officers, artillerymen, and other auxiliary troops to have a means of defending themselves, especially as it was not always practical for them to have a full-length rifle or carbine.
Traditionally, soldiers (infantry and cavalry alike) and officers had carried swords for both personal protection and use in combat. The development of firearms in the mid-14th century changed the way battles were fought, and by the late-15th century it was no longer especially practical to close to hand-to-hand combat range to engage one's opponents, owing to the prevalence of pikes and musket-fire (pike and shot) on the battlefield.
Training was also a factor—it took a very long time to train new recruits in the use of longbows and swords—whereas the basic operation of an arquebus could be taught in a comparatively short time. As a result, swords were retained only by officers (who were less likely to be at the front of the pike-and-musket hedge) and by cavalry, for whom early single-shot handguns were of limited use.
The invention of the revolver in 1836 finally made a "service pistol" practical, as prior to this pistols had largely been single-shot weapons usually of no particular standardized pattern.
Although officers traditionally had been obliged to buy their own weapons, non-commissioned officers (NCOs) and other enlisted personnel were generally issued their weapons (which they were then expected to either pay for or return to the quartermaster if they were promoted). Service pistols, on the other hand, were generally issued to officers, NCOs, and others who needed to carry personal weapons as part of their duties. Hence, it was quite common for officers to carry government-issued service pistols in combat.
The first service handguns were revolvers, but the development of semi-automatic pistols (the first practical example being the Mauser C96 "Broomhandle") gradually led to their replacement by semi-automatic handguns, such as the well-known German P08 Luger, the first semi-automatic service pistol to be widely adopted by an industrialised nation.
The British Army was the last major military service to adopt a semi-automatic service pistol as a standard sidearm, phasing out their Webley Mk IV, Enfield No 2 Mk I, and Smith & Wesson Victory revolvers in 1969, after which the Browning Hi-Power became the Army's official service pistol.
Modern issue.
Special operations soldiers often carry a handgun as a secondary weapon to serve in a supplementary capacity to their primary weapon (a rifle, carbine, submachine gun, or shotgun); this practice is not as prevalent among conventional soldiers. Soldiers who do not serve in a direct combat role are often issued a pistol (such as officers, artillery crews, and other rear-echelon personnel), but conventional riflemen are not generally issued a pistol as part of their standard kit. However, drivers are often issued a handgun since while driving, their rifle will be stowed on a rack and thus difficult to make ready quickly in an emergency whereas a handgun is more easily accessible. Service pistols are issued to military police and other soldiers acting in a law enforcement capacity as part of their duties.
The tradition of issuing pistols to officers as a primary weapon is being phased out by many nations. The United States Marine Corps, for example, recently began requiring all enlisted personnel and all officers below the rank of Lieutenant colonel to carry the M4 Carbine as their primary weapon. British officers on combat duty are also normally issued with the standard rifle, but are not required to carry it with them at all times; for example, while operating as support staff the rifle would be stored in the base armory, though this is the same for most support staff.