I'd say the answer to that is: "sometimes".
I've raised both pigs and cattle in the past, and pigs are definitely the more intelligent of the two. They're much more likely to be agitated by a rapid change of environment. Both are herd animals, so the agitation of one tends to agitate the others.
In the context of a slaughterhouse, the biggest things that should be done to reduce agitation is to reduce their exposure to unfamiliar sights and sounds, give them time to adjust to their surroundings without being disturbed, limit the duration of disruptions, and keep them in smaller groups.
In my experience in the situation I described in my top-level post, some pigs definitely knew that something bad was happening when they were let in to the kill room. Completely subjectively, I'd judge that maybe 10-20% of them acted like they felt threatened at that moment.
In that particular operation, we'd slaughter no more than ~50 pigs at a time - enough to develop an efficient process and for the workers to be proficient with it, but not enough to justify an expensive mechanical system optimized for throughput.
The person responsible for killing the animal had probably done so thousands of times in the past. It took less than fifteen seconds from the time the pig entered the room to the time it lost consciousness.
For what it's worth, I never saw an instance of the slaughtering method failing on the first try, but there were arrangements in place in the event that it did. A second bolt gun was kept armed and within reach in case the one in use failed. Given that this was a small "family" operation, there was also a .45 handgun a few feet away that could be used in an emergency if there were no other option to end an animal's suffering.
I was in my mid-teens when I worked the floor there, and the training was short but effective. For the first half dozen or so that I killed, a more experienced person was there overseeing, and was ready to step in if necessary. I was given the opportunity to "practice" on previously-slaughtered animals so I knew exactly where to place the gun, how loud it was going to be, etc., so by the time I was in the position to do it for real I had no doubts about what to do and could do it quickly.
Finally, I'll add that agitation - or "stress", or "panic", or whatever you want to call it - is a financial concern as well as a moral one. An agitated animal is likely to injure themselves before being slaughtered, which reduces meat quality and yield. Large companies are definitely optimizing to reduce that. My concern is that they're optimizing the process to maximize yield to the detriment of animal welfare. To be fair, I don't know if that's the case. I've not worked in a larger facility.
I live in an area with a ton of pork and poultry processing facilities. Given that my assumptions around the slaughter methods were shown in this thread to be incorrect, I think I'll see if I can't get access to one to tour their operations and see for myself.