Thorough research on the suspend process of linuxpm
Source: Internet
Author: User
A thorough study of the linuxpm-suspend process-general Linux technology-Linux programming and kernel information. The following is a detailed description. Pm-suspend normal process: f 7
1. pm-suspend --> symbol link to/usr/lib/pm-utils/bin/pm-action
2. pm-action put the suspend field of the extract command in the ACTION variable by processing
Use suspend as the parameter to call pm_main in/usr/lib/pm-utils/functions
3. pm_main
Pm_main ()
{
If [-n "$ PM_LOGFILE"]; then
Exec> "$ PM_LOGFILE" 2> & 1 # redirect all echo output to this file if/var/log/pm-suspend.log exists
Fi
Take_suspend_lock | exit 1
Rm-f "$ INHIBIT"
Run_hooks "$1" ## call the run_hook function with suspend as the parameter
# Call do_suspend for real sleep
If [! -E "$ INHIBIT"-a "$ (type-t" do _ $1 ")" = "function"]; then
Sync; sync
"Do _ $1"
Fi
Run_hooks "$2" reverse # Call run_hooks resume reverse
Remove_suspend_lock 200
Return 0
}
Take_suspend_lock ()
{
VT = $ (fgconsole) # obtain the forward ground console value, VT = 7
Chvt 63 # Switch to VT 63
If [-f/. suincluded]; then # if the. suspend file exists under/, the pid value is read from the file.
Read pid </. susponded
If [-d/proc/$ pid]; then # if a corresponding entry exists in/proc, the function exits and returns to pm_main. The pm-suspend command exits.
Return 1
Fi
Fi
# The above is actually to test whether the user has run a pm-suspend command, and the system will not run pm-suspend continuously
Echo "$">/. suincluded # print your pid to the/. suspend file.
Rm-f/var/run/pm-suspend
Touch/var/run/pm-suspend
Return 0
}
Remove_suspend_lock ()
{
Rm-f/var/run/pm-suspend
Chvt 1 # Switch to VT1
Chvt $ VT # Switch to the VT before hibernation
Openvt -- sh-c "usleep $1; rm-f /. sushortded>/dev/null 2> & 1 0 <& 1 ">/dev/null 2> & 1 0 <& 1 & # Open VT (that is, VT7 ),
# Execute sh: Sleep for 200 seconds, delete the/. suspend File
}
4. The main task of the run_hooks function is to execute all the scripts in/usr/lib/pm-utils/hooks.
The script naming method under the hooks directory is: Number + name to hook
In suspend mode, scripts with small numbers are executed first. In resume mode, scripts in reverse order are executed to ensure that suspend-resume has the correct sequence.
5. The design company's stuff below will not be shown.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service