Basically if I lived in a pre gunpowder city that was about to be sacked by an invading army, what was going to happen to me, my family and my city.
I kind of have this idea of everyone gets killed, enslaved or raped but it seems like people continue to live in these cities afterwords so some people must survive?
In the ancient world, depending on where you lived, who was attacking you, what the leaders of your city did to appease or displease the invaders, etc all mattered. If you are specifically asking what would happen if the invaders were 'mad' at you and wanted you to suffer, well, you are basically in for a truly terrible experience.
Lets look at a historical example, Alexander the Great and the city of Tyre. Tyre was a city-state in the area of the middle east, near modern day Lebanon and Israel referred to then as Phoenicia. The Phoenicians were the famous naval settlers of several colonies of the Eastern Mediterranean, but their most famous colony was that of Carthage in modern day Tunisia. Well here comes Alexander the Great on his way to go liberate Egypt. When he arrived to the city of Tyre, he demanded their capitulation and ordered that he be allowed to make a sacrifice in their temple of Milqart. Tyre denied his request and responded by murdering his emissary. Alexander, as I previously asked above, was no-doubt 'mad' at the entire city of Tyre and swore that he would conquer them.
Long story short, Alexander built a giant causeway (Tyre is actually an island city) to their walls, took the city and then punished the people immensely for what he took as a disrespect. There were tales of Alexanders cruelty that still survive today. It is said he massacred half of the city, sold 30,000 women and children into slavery, crucified 6,000 soldiers on the beaches of Tyre and burned the city down. There is a tale though, that Alexander spared the people he found hiding in the Temple of Milqart, including the king of Tyre. So while the regular people and military-aged men were punished, the wealthy nobles and leaders of the city were actually spared. Sound fair, huh?
In the medieval period pre-gunpowder, the Mongols were infamous for butchering entire cities that defied them militarily. The most famous tale involves the city of Baghdad. The rulers of the city (which was said to be the most beautiful, wealthy, intellectual, and cosmopolitan city in the world at that time) turned down the Mongol emissaries and beheaded them when they pressed on further. The Mongols came back and destroyed the city completely. It is said that the Euphrates river was dyed black from the ink of the books of Baghdad and that the city never recovered, up until the modern day. (Which has only worsened due to the recent political events in Iraq)
Basically, if you were a poor person who wasn't able to leave the city before being sacked and you had a wife and child, you were not in a very good position. Most likely you would have been killed, your wife would've been raped and enslaved, and any children you would have would be enslaved as well. Your best bet would've been to hide in a temple or religious building, or some part of the city that was defensible or at least well protected like a citadel or fortress. If you were poor, good luck. If you were rich or middle class, you might've tried to surrender yourself into slavery, or make an attempt to bribe the attackers.
Think of the cities and villages of Gaul. Obviously when Caesar took control of them the people would most likely be enslaved, but Caesar also had many Celtic allies in Gaul to replace the populaces of these towns. Some towns were absolutely destroyed because the people were all enslaved or killed, but there were also Romans moving into Gaul including slaves and local tribes looking to take their fertile farmlands and strategic positions.
Hope this helped.