If you can keep a bead on the welfare of the department you're working in if its a large corporation. Smaller startups, its usually pretty obvious.
My two examples:
Worked at a telecom company during the CLEC, deregulation days. Group of private investors devised a scheme whereas they would grow this small existing telecom company and then sell it off to a larger company and make millions. They had about $3M altogether invested. CEO burned through $2M in 6 months for stupid stuff like sky boxes at the local sports teams arena's and other frivolous stuff. Sales were slumping, we were getting a lot of calls from unhappy customers during installs. There were multiple closed door meetings with the investors. The funny part was the conference room had really thin walls and there were a lot of yelling during those meetings. You didn't have to be a genius to know whatever they had planned, wasn't happening. The final coffin was when one of the network guys told me he overheard one of the closed door meetings. He said the group was split on whether to continue the company, or fold up shop. Threats of lawsuits essentially ended the meeting and they all marched out of the office in a hurry. To me, I already felt like this wasn't going to last. Now I had confirmation and started planning to find another job.
I also worked at a huge corporation in their development department. We were a new team working on some big initiatives the company wanted to get going. Everything was going pretty smoothly. Then the recession hit in 2008. Then over the course of several lunches with various people in other departments, I found out several departments were having layoffs, reducing budgets, and putting projects on hold. Pretty soon, a lot of the teams we were working with which had dozens of people working on them, suddenly only had two or three developers. It really felt like the walls were closing in so I started looking. Literally the day I put in my two week notice, my manager said they were planning on putting our two projects on hold and laying everybody off within the next two weeks.
I think it just comes down to paying attention to what's going on around you. There's always signs things are not going well, you just have to recognize them when they present themselves. At both places, there were people who held on until it was too late. One of the techs at the telecom company said he came in one morning and the office was dark, and a security guard told him they had shut down the company and because of legal reasons, nobody could go in the office.