Reputation: 24433
Is there a way to pause a Bash script, then resume it another time, such as after the computer has been rebooted?
Upvotes: 3
Views: 4445
Reputation: 11862
If this applies to your script and the job it does, add checkpoints to it - that means places where all the state of the process is saved to disk before continuing. Then have each individual part check if the output they have to produce is already there, and skip running if it is. That should make a rerun of the script almost as efficient as resuming from the exact same place in execution.
Alternatively, run the script in a VM. Freeze the VM before shutting down the real system and resume it afterwards. It would probably take a really huge and complex shell script to make this worth it, though.
Upvotes: 1
Reputation: 107080
Intriguing...
You can suspend a job in BASH with a CTRL-Z, but you can't resume after a reboot. A reboot initializes the machine and the process that was suspended is terminated.
However, it might be possible to force the process into a coredump via a 'kill -QUIT $pidand then use
gdb` to restart the script. I tried for a while, but was unable to do it. Maybe someone else can point out the way.
Upvotes: 1
Reputation: 1765
The only way to do that AFAIK:
Upvotes: 2
Reputation: 81724
You can't pause and resume the same script after a reboot, but a script could arrange to have another script run at some later time. For example, it could create an init script (or a cron job, or a login script, etc) which contained the tasks you want to defer, and then removed itself.
Upvotes: 1
Reputation: 2354
Try Ctrl-Z to pause the command. I don't think you can pause it and then resume after reboot unless you're keeping state somehow.
Upvotes: 1