If the person who is the subject of a petition for the writ of habeas corpus is detained upon a criminal charge and the district attorney is in the county, he shall be notified of the hearing. If he is not, the notice shall be given to the prosecutor of the criminal charge.