There is a custom known as "Kapparot" which is observed in many communities on Ereb Yom Kippur. One takes a chicken and swings it around his head while reciting a text proclaiming that the slaughtering of the chicken should take the place of any punishments he deserves to endure. Men use a rooster for Kapparot, whereas women use a chicken. (Other people prefer using money for Kapparot and then giving it to charity, and this practice is certainly valid.)
The custom of Kapparot requires a pregnant woman to take three chickens – one for herself, and two for the fetus. Since she does not know the infant’s gender, she must take a rooster in case it’s a boy, and a hen in case it’s a girl. If she knows she is carrying twins, then she must take five chickens – one for herself, and two for each fetus. If she knows she is carrying triplets, then she takes seven chickens.
The Halachic authorities debate the question of whether a woman may rely on an ultrasound to determine the baby’s gender for the purposes of Kapparot. Rav Yitzhak Yaakob Weiss (1901-1989) wrote in a resposum that he consulted with a leading obstetrician who said that the infant’s gender cannot be definitely determined based on an ultrasound, and he thus ruled that such a determination cannot be relied upon with respect to Kapparot. Hacham Ovadia Yosef, however, rules leniently in this regard, and allows a woman to rely on an obstetrician’s reading of the ultrasound and take just one rooster or hen on this basis. Hacham Ovadia notes that in any event, taking Kapparot for an unborn child is not required according to the strict Halacha, and thus, for example, if a pregnant woman cannot afford extra chickens for her fetus, she may bring only one hen for herself. Therefore, since to begin with we are not dealing here with a strict Halachic requirement, a woman may certainly rely on the ultrasound and bring only a rooster if the doctors say she is having a boy, and a hen if it is a girl. This ruling appears in Yalkut Yosef – Yamim Nora’im (p. 293, in a footnote).
A woman who is within forty days of conception, and learned she was pregnant through testing, does not have to bring Kapparot for the fetus. This is ruling of Rav Shemuel Wosner (contemporary), in his work Shebet Ha’levi.
Rav Wosner also mentions that if a pregnant woman brought Kapparot on behalf of the fetus before Yom Kippur, and she gave birth before Yom Kippur, she does not have to bring Kapparot again for the newborn infant. Although some Halachic authorities dispute this ruling, Hacham Ovadia Yosef follows the lenient position.
Summary: A woman who is more than forty days pregnant must bring Kapparot for herself and for the unborn child. If she does not know the child’s gender, she must bring both a hen and a rooster for the child, but if she was informed of the gender through an ultrasound, she may rely on this information and bring only a rooster or a hen. If she did Kapparot for the infant and then gave birth before Yom Kippur, she does not have to bring Kapparot again.