SUNNYVALE, CALIF., FEB. 17 -- The killing was quick and brutal: Richard Wade Farley needed only 30 minutes, in a rampage through the tiled corridors of a prosperous computer company here. But police needed five hours to talk Farley out of the building -- with a soft drink and a sandwich -- so they could count the seven dead and four injured.

Farley, firing shotgun blasts at his former colleagues at ESL Inc. -- and into the screens of computers that symbolize Silicon Valley prosperity -- apparently was avenging his dismissal and an unrequited obsession with ESL engineer Laura Black.

Farley, 39, a software engineer dismissed in 1986 for alleged sexual harassment, was in a Santa Clara jail cell today, charged with murder. Black, 26, who had rejected his advances, was in stable condition with chest, shoulder and spinal wounds.

A court hearing had been scheduled today on her request for a restraining order against him.

But this city west of San Jose was not the only place where Americans were killed Tuesday as they went about their workdays. Farley was still holding police at bay when a woman walked into a hospital emergency room in Pittsburgh, killed a mental health caseworker and took three hostages before surrendering Tuesday night at 8:30. In Chicago, a woman walked into the Midwest Stock Exchange and fatally shot a clerk, her ex-boyfriend.

A growing number of people are discovering that being where they belong is no insurance against being in the wrong place at the wrong time. "There is a tremendous sense of becoming vulnerable," said Cecile Currier, a clinical social worker who counseled many of ESL massacre's victims and their relatives.

Juanito Yapdiangco, whose wife, Emelina, risked a short, guarded telephone call to him from her hiding spot during the siege, said today that she was devastated by what had happened to her coworkers and was trying to put it completely aside. "She wants to forget about it," he said.

Police said Farley drove his rented mobile home into the ESL parking lot about 2:55 Tuesday afternoon and hesitated briefly before draping himself in two bandoleers of ammunition. Then he armed himself with three handguns, including 9mm Browning semiautomatic pistol and a .380-cal. semiautomatic pistol, a .30-06 high-powered rifle and a 12-gauge shotgun -- the weapon used in all the killings.

Lt. Ruben Grijalva, the police negotiator who persuaded Farley to surrender, said Farley indicated that initially he only wanted to damage ESL property but began to shoot people he thought were trying to stop him.

His first victim died just outside the front door, police said. With the shotgun, he destroyed the card-operated security lock and door, entered the building and killed his next two victims, a man sitting behind his desk on the first floor and another on the landing of the stairwell to the second floor.

Sunnyvale police Capt. Al Scott said Black had shut and locked her second-floor office when Farley found her and shot at her through the door. Also injured were Richard Townsley, wounded in the chest, arms and legs when he tried to help others get out of the building; Gregory Scott, wounded in the chest, and Patty Marcotte, who broke her right arm as she escaped.

Police identified the five men and two women killed during the rampage as: Helen Lamperter, 49; Glenda Moritz, 27; Joe Silva, 43; Wayne Williams, 23; Ron Reed, 26; Lawrence Kane, 46; and Ron Doney, 36.

The locations of bodies of the two men and two women killed upstairs indicated that Farley had chanced upon them in the halls, police said. About a half hour after he entered the building, Farley sought refuge in a second-floor computer room and called the company's security office. They put him in touch with police, who began a long conversation, interrupted occasionally when Farley suspected that someone was approaching his refuge.

During the five-hour conversation, he told Grijalva: "I'm not crazy. I know I will die as a result of this." Police said he expressed disappointment not only at his failure to win Black's affection but at mounting debts and the loss of his house and home computer, which he blamed on his firing.

In the end, Farley agreed to leave his weapons and gave himself up in exchange for "a No. 26 {sandwich} from Togo's and a Diet Pepsi," police said.

Police said Farley's dismissal seemed to be related to his harassment of Black, but Cartwright said her records -- incomplete because the personnel office is sealed off -- indicated that he was dismissed simply for "poor job performance."

In the early evening, Farley told police that they could enter the building to release workers who had been hiding under their desks behind locked doors. About 26 people, all uninjured, emerged. The wounded had been left or been brought out in the first few minutes after the shooting.

ESL spokeswoman Edie Cartwright said company security guards are not armed. Farley appeared so suddenly, with so much weaponry, that the company's locks and other security procedures were useless, she said.

Police said that they did not know where Farley obtained his guns but that he apparently had been familiar with firearms since his youth. He served 11 years in the Navy, Scott said, and received a "secret" security clearance from the Defense Department when he was hired at ESL.

ESL, a subsidiary of TRW, reported record revenue of $335 million last year in mostly defense-related contracts such as surveillance systems. Today, its two-story Building M5 remained sealed off as police inspected the wreckage inside.

Currier, the social worker, said families and employees met at her hospital-based counseling service, Concern EAP, to discuss the tragedy today. "First they try to deny it, it seemed so unreal," she said. Then they are obsessed with details, looking for someone to blame, including themselves.

But often the process ends when they conclude that the hurt could not have been prevented.

"Which is a paradox," Currier said, "because that means they will never feel quite as safe again."