In general exactly what others have said. Stop if you are in a safe location or get yourself to one and stop. Layer up, it is easier to stay warm than to get warm (obviously location and time of year dependent). If you are really lost activate whatever SOS device you have, which to be perfectly honest you should have in this day and age. The versions that allow two way comms are best, like the in reach or spot x. Once you do that STAY WHERE YOU ARE. Signaling with a whistle/signal mirror are also very helpful. Also make sure some bit of gear is bright, it could be your pack, a pack cover, tarp, or jacket, or all the above. More importantly there are some ways to help not get lost. First periodically look back the way you came, this can help if you get slightly misplaced to retrace back to a last known area or trail. Modern phones with a good outdoor map program with the maps downloaded are great. Just remember to keep it in airplane mode, which will preserve battery but the gps receiver will still function. Carry a compass and map as backup (also learn to use them). Also you can use something like fatmaps prior to your trip to get an idea of terrain features, which is especially useful in mountainous terrain. I also always have 2 headlamps, one really bright primary and one small and light one as a backup. The backup usually goes in my first aid kit so it is easier to find and even switching packs I will at least have that one.