Like boxes falling off a crowded shelf, two major grocery chains have tumbled into bankruptcy in the past month. Several other food retailing companies are inching closer to the edge as well.

This lastest round of failures and close calls has sent fresh jitters through an already tremulous industry. Pinched by rising costs and steep interest rates, frustrated by sluggish increases in shopper volumes, grocers recently have been left holding too many empty, expensive bags.

Of course, food retailing has never been an easy business. Traditionally, grocers have earned only a cent or less on every dollar's worth of food sold. The industry's history is cluttered with price wars and other forms of competitive bloodletting.

But in recent months, already narrow profit margins have shrunk even narrower. And food retailers - the people who turned the concept of a chain into a workable business phenomenon - are discovering dangerously weak links.

"There are more firms now visibly in trouble than in my recollection," declared Robert Aders, president of the Food Marketing Institute, an industry lobbying group. This is not to say the whole industry is beleaguered. For every troublesome situation, there are several prosperousones, Adler stressed Also, a spate of independents are entering the grocery business, building on the rubble of those scurrying out.

"It's not a shake-out," said Tim Hammonds, another food institue official. "But it is certainly a shake-up."

Those in trouble include:

Food Fair Inc., the country's eighth largest chain, which last month filed for a Chapter XI bankruptcy seeking court protection from its creditors. Company officials insist Food Fair is still a strong firm but has run into a temporarily severe cash flow crunch. To help it over the rough spot, the company has decided to sell 89 Pantry Pride and Hills supermarkets in New York and Connecticut. The chain owns 440 supermarkets and 79 J.M. Fields discount stores.

Allied Supermarkets, which many observers believed would solve its financial problems despite four years of losses. It also has filed for Chapter XI protection. The company reported a loss of $13.1 million last year and $9.6 million for the first nine months this year. It had begun a retrenchment program, selling off more than 200 stores in the last two years. But to stay in business, it still had to borrow heavily at interest rates that recently topped 16 percent.

A&P, whose problems haven't gone away, either. In the past four years, the supermarket giant has closed half its stores, replaced its top management and spent hundreds of millions of dollars on new facilities. But it still has 1,700 stores that together lost nearly $17 million this year.

First National Stores, a Boston-based chain. Earlier this year, the company merged its 115 stores with Pick-N-Pay of Cleveland, hoping to get a new burst of financial strength. But the chain remains strapped by a string of supermarkets in older northeastern neighborhoods.

Confronted with such troubles on the retailing end, others in the food business are worried about a chain reaction. There already has been fallout from the Food Fair action. Filigree Foods, a New Jersey wholesaler and major Food Fair supplier, was forced into bankruptcy two weeks ago after being stuck with a $7 million claim against Food Fair.

The big worry in the industry now is whether major suppliers stay calm. Because supermarkets keep large inventories, they are beholden to their suppliers for credit. They constantly buy and so are constantly in debt. All that's necessary for several bankruptcies to snowball into industry disaster is for suppliers to get nervous, demand immediate payment of accounts outstanding and insist on cash for future deliveries.

Earl Smith, Allied's chairman, blamed his company's fialure on just this set of events. "Our meat packers began asking for payment on delivery," said Smith. "In addition, some meat packer employes began taking Allied's checks to our banks rather than cashing them at their own banks. They went so far as to tell the bankers we were going into bankruptcy. Their actions upset our bankers, and the final blow was that we were forced to adopt a cash position for fresh and processed meat purchases in order to have enough meat in our stores."

Suppliers deny applying extra pressure on grocers, though they say it is only natural they should be eyeing problem accounts more cautiously.

In is possible to be in the supermarket business and still get rich. Profitable chains such as Kroger, Safeway and Giant attest to that. Why are some doing so well while others are floundering? The answer rests with management and the aggressive steps some companies have taken to close unprofitable stores, renovate others, tighten controls and adopt a fascinating assortment of technological innovations.

"The industry is going through a major change," said Willard Bishop, a food industry consultant in Chicago. "It's a process of a mature industry further adjusting."

Born in the 1930s, the food chains were once the masters of retail merchandising. With the turnover of a huge volume of food each year, they profited handsomely on razor-thin margins. As the population grew, sales and profits soared.

That dominance has been shaken by two sets of factors. First, a slower growth in the number of shoppers and the rise of the dining-out generation. A declining birthrate, plus demographic changes such as more working women and the decline of the conventional family, has put supermarkets on a collision course with fast-food restaurants and, to a lesser degree, convenience stores for control of consumers' food budgets.

Americans now eat 18 percent of their meals aways from home and spend 36 percent of their income doing so, according to the U.S. Department of Agriculture. Sales of the nation's 28,000 convenience stores, which offer a limited line of groceries but stay open at odd hours, shot up by 20 percent last year. Industry observers predict that convenience stores, which now take 5 percent of the food budget, will soon outnumber the nation's 33,000 supermarkets.

Even more critical are rising operating costs and intense competition within the industry. It is s popular belief that inflation doesn't hurt supermarkets much because they can jack up prices in a hurry and sell off lower-cost inventory at at newer higher prices. But grocers say their stores are labor-and energy-intensive operations that don't suffer inflation well. For instance, the price of food consumed in the home increased 6 percent last year, while supermarket chains' labor costs, which constitude two-thirds of a food store's gross margin, rose by 12 percent and energy costs jumped 30 percent. The average supermarket earned only four-fifths of a cent every dollar sold last year.

With too many stores chasing too few customers, and costs closing in, many chains have tried to do what they know best: cut prices and prey on their competition. Industry observers cite current price wars under way in Houston, Cleveland and Detroit.

But increasingly, supermarket chains are doing other things aimed at restoring profits to respectable levels. They are testing different formats, and are replacing smaller stores generally with larger ones, hoping for economies of scale. The new supermarket today averages 30,000 squares feet compared with 21,000 a decade ago - and it looks different on the inside, too.

Supermarkets aren't selling just food anymore. In fact, some of them seem to be selling more of everthing and anything but food. The reason is that food retailers can make a much larger profit on nonfood and specialty items. It's not uncommon to see gourmet sections stocked with Godiva chocolates and snails, deli sections featuring artichoke hearts and lasagn, and other special sections ranging from floral boutiques to hardware counters.

Even the basic supermarket format is being questioned. Some of the larger chains are experimenting with such varied designs as warehouse stores, limited-assortment stores and combination stores. In the Washingtonm area, Giant Food Inc. as a rule now includes a drug store in every new food store it builds.

"It look like there's no standard store type emerging," said Hammonds, the food institute offical. "You're going to have a mix of stores in many neighorhoods. There isn't any prototype anymore."

The trick in all of this is to match the store to the market, to give shoppers in a particular community the kind of store they want. It is the increasing importance of the local focus in food retailing that has effectively eliminated the possibility of a national grocery chain emerging in America. A&P was the last of the great chains finally to accept this and shrink its operation.

For this reason, too, the independent grocer continues to thrive. In the last two years, independents outstripped chains in both sales and productivity growth. Today, total grocery sales are split evenly between independents and chains. (An independent is defined as the owner of 10 or fewer stores.)