mac restarting for no reason

Dear experts,

Today something happened with my mac computer. I was working with no problems, then I went for a cop of coffee and when I came back I found a black screen and a very faint form asking for my password (It was really hard to see that form). so I try to press the power button that nothing happened. I pressed it for like 10 seconds (as I used to do with my windows computer) and it seems something sounded but I kept getting the black screen. then I decided to plug it in and and plug it out and for some reason it worked (the battery was at 57%), but it seems it restarted but itself because I was prompted to enter my mac password.
I have no idea what happened, but of course it closed all the programs that I was working on..
Not sure how to check it is have a virus of a hardware problem. Could you please help me to troubleshoot this issue?

Thanks in advance,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sigurdur ArmannssonDesigner Commented:
Please mention your mac model and system version.
glepizaAuthor Commented:
Sure, it is a Mac OS X version 10.8.4
Processor: 2.6 Ghz
Memory: 8gb
Eoin OSullivanConsultantCommented:
The behaviour you describe does not sound like a virus and probably not a hardware fault.  Most likely it is a software (application or OSX system issue).

Holding down the power key for 10 seconds will initiate a reboot so that is probably why it restarted after you pressed it in for so long.  Pressing  the power key once normally puts a laptop into sleep mode.

When you left the computer .. several things could've happened but it is most likely that the Screensaver or Power Saving Sleep mode could have initiated as the laptop was not plugged in.

Some programs and applications can have issues with the sleep process and may cause the OSX system to hang or freeze during the sleep process.

Open the System Preferences and look in the Energy Saver pane.
You can set how the computer behaves when running on power, battery etc.
You can choose how long before the Display or the Computer goes to sleep.

To awaken the computer from Sleep you press any key (you can enable Password protection on wake from sleep in the 'Security & Privacy pane in System Preferences).

The current version of OSX also has a feature called PowerNap which let the Mac perform certain activities even when running in sleep mode

There is also a checkbox that allows the Mac to reboot automatically after a crash (if this is enabled you might wish to disable it).  If it WAS enabled and OSX or an application caused a crash this might also explain why your Mac rebooted automatically.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
glepizaAuthor Commented:
Thank you experts, I really appreciate all your answer. I haven´t had more problems with my computers, but I am going to take into account your suggestions.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Mac OS X

From novice to tech pro — start learning today.