Usually, this question becomes part of the divorce agreement. However, the IRS has its own ideas about this tax exemption which is printed below. The IRS does not want to get embroiled in family disputes. Nevertheless, here is what is written in the tax law:

Treasury Decision 9408: The custodial parent is entitled to the dependency exemption for the child regardless of what the divorce decree or agreement states, unless the non-custodial parent attaches a signed waiver effective for that tax year. The release of claims for an exemption must be either on Form 8332, Release of Claim to Exemption for Child of Divorced or Separated Parents, or written declaration for the sole purpose of releasing the claim that conforms to the substance of Form 8332. For the purposes of this decision, where one or both parents have the right to physical custody for over one-half of the calendar year and the child is under the age of the majority under state law, the parent with whom the child resides longer during the calendar year, is the custodial parent.