It depends on the type of distress, but generally the easiest way to communicate a problem is to use the radio and describe the situation. However, there are some special transponder codes which will get the attention of any controller which has you on their radar screen.
- 7500 indicates a hijacking
- 7600 indicates a communications radio failure
- 7700 indicates an emergency
What happens after switching to one of these beacon codes depends on the scenario. In any of the cases, ATC will attempt to make contact with the aircraft. In most cases, they will also try to vector other traffic away from the aircraft for everyone's safety (especially true in the case of a hijacking).
I assume your question is primarily asking about a hijacking scenario. A recent, and very odd, example of 7500 being used is Ethiopian Airlines’ Flight 702 where the co-pilot actually hijacked the plane and squawked 7500. Unfortunately, pilots don't always have the time to reset the transponder if they are engaged in a physical fight in the cockpit. Also, the first step of the hijackers may be to turn off the transponder (this is what happened on 9/11), but if a controller is able to see the 7500 squawk, even briefly, it may help the controller understand what is happening if communications are lost, and to alert the military, if necessary.
As for the other two "distress" signals:
For 7600 (lost communications) they will probably ask "if you're receiving this, ident" or "if able, reset transponder code XXXX." If you comply with their request, it indicates that you can receive messages, but cannot transmit. A tracon or center controller might ask you to ident to acknowledge further instructions (when you ident, your datablock flashes on their screen), or just watch your actions closely. If you're on with a tower controller in visual conditions, rocking your wings or flashing your landing light can be used to acknowledge instructions. At towered airports, light-gun signals are used to give landing clearances when a pilot cannot receive radio communication.
For 7700 (emergency) they will try to inquire as to the state of the emergency and offer any assistance possible, such as providing you suggested headings or information about nearby airports.