How to know ahead of time if food will be served during a flight? Ideally, at which time(s) and the menu options.
As JoErNanO said, this is often printed somewhere on your itinerary, though it usually says little more than something like "Dinner, Breakfast."
Specific menus vary wildly, so airlines don't generally make them available ahead of time. The exceptions are generally low-cost carriers that require you to purchase meals in advance or premium services like Singapore's Book the Cook. Every airline's website should have a page with meal information. When food is available for purchase, more details on the choices may be available (e.g. for United Domestic/Canada/Latin America flights).
Otherwise, you might find some information from online trip reports. A search for your flight number, "trip report," and "economy" or "business" may bring up someone who has written a detailed report on their flight, including meal information. While menus change regularly, this should give you a decent idea of what services to expect and when. Frequent flyers on forums like FlyerTalk sometimes take pictures of their (usually non-economy) meals and post them.
Buying food at the airport to bring on-board is often a more appetizing choice.
The subscription service ExpertFlyer shows the configured meal options for most flights in the world, as configured by the operating airline.
Most airlines serve meals on international and long-haul flights, and domestic flights that are longer than some threshold, and operate close to usual meal times in the country. In general, when meals are offered, meal services typically starts about an hour after take-off. On long-haul flights, there is often a second meal, typically lighter than the first meal, offered around one to two hours before arrival. On very long flights there may be a mid-flight snack service or available on request.
In general, the higher the cabin the greater the quantity and flexibility of the meal service. Many airlines offer a la carte or dine on demand choices in business and first class on international and long-haul flights.
Your booking will indicate which meals are served. Typically, shortly after takeoff and shortly before landing. If you ask nicely, the Flight Attendants will usually accommodate alternate times.
Depending one the airline, you may be able to view the menu up to 30 days before departure if they offer a choose you meal option. Otherwise, unless you know someone in either catering department, you find out onboard like everyone else.