The authorities don't announce the executions ahead of time. They usually take place in the early morning, and people in the neighbourhood realise that an execution is going to take place when they see the stage being set up.
At all the executions I have been to, I have noticed that the people who gather to watch them are above all curious. They just wanted to see what it's like to see a human die. Sometimes, people who stop to watch don't realise exactly what's going on until it's too late, and are quite shocked. Meanwhile, some have their young kids with them -- I once suggested to a mother that she may want to cover her little boy's eyes, and she said, "oh, he's a kid, he'll forget about this anyway".
Usually, everyone stays silent. In recent years, people have started bringing their mobile phones to take pictures and short films and put them on social networks.
The onlookers often feel sympathy both for the victims of the crime, and the criminal who is about to die. People have told me things like, "it's such a shame, he's so young". And in the next breath they'll say, "but then again he killed someone, so he deserves it."
I witnessed an execution of a famous criminal in southern Tehran once. He had killed multiple people, and everyone in the neighbourhood was terrified of him. But at his execution, he addressed the crowd. He admitted his sins and talked about the difficulties he had faced in his youth. The crowd started to feel sympathy for him. In my opinion, these executions have no deterrent effect on the population.