This depends on your local Laws. Usually the Sale has to be finalized by a Judge before the home is awarded to the Buyer (or Bank if no one bids on it) The Sheriff department will be serving you. I would suggest you contact them.
If you are trying to sell your home in a standard sale or a short sale, the bank in most instances will agree to delay the trustee's sale. I would contact the bank about that if you are selling. If you do not sell and it does get foreclosed. The bank or their representative will contact you to negotiate a move out time. They will obviously want you to move as quickly as possible and may even offer you a financial incentive to do so. They also may proceed with an eviction process similiar to a tenant who isn't paying their rent, so that would depend on the eviction laws in your area.
That depends on specific circumstance and how much time the judge grants you before a foreclosure/auction date is set. I have seen it from 30 to 120 days. If your home is listed for sale you can request more time to sell the property. However, again that depends on your specific circumstances.