Difference between revisions of "Simple loop"
(reorganized, simplified, fixed english etc.) |
(crtools -> criu) |
||
Line 18: | Line 18: | ||
=== Run (isolated) === | === Run (isolated) === | ||
− | Now, if you try to simply run and try to dump such a program, | + | Now, if you try to simply run and try to dump such a program, criu will fail. The reason is a program you launch from the shell shares some common resources with the shell, notably its session and terminal. Criu has a built-in check that makes sure there are no such resources. |
To remove the dependency on a current terminal, let's executed our script in a new session and redirect its output to a file: | To remove the dependency on a current terminal, let's executed our script in a new session and redirect its output to a file: | ||
Line 36: | Line 36: | ||
Dump it: | Dump it: | ||
− | # | + | # criu dump -t 2221 -vvv -o dump.log && echo OK |
OK | OK | ||
Line 56: | Line 56: | ||
Restore the test process: | Restore the test process: | ||
− | # | + | # criu restore -d -t 2221 -vvv -o restore.log && echo OK |
OK | OK | ||
Line 64: | Line 64: | ||
For that we need to execute our test script or another program (e.g. "top") from a terminal without any redirection. | For that we need to execute our test script or another program (e.g. "top") from a terminal without any redirection. | ||
− | Note | + | Note criu only supports [http://en.wikipedia.org/wiki/Pseudo_terminal Unix98 PTYs]. |
=== Run === | === Run === | ||
Line 75: | Line 75: | ||
=== Dump === | === Dump === | ||
− | Currently | + | Currently criu doesn't support a stopped task, so "criu dump" must be executed from another terminal. |
− | # | + | # criu dump -t 2621 |
(00.012929) Error (tty.c:1022): tty: Found dangling tty with sid 940 pgid 2621 (pts) on peer fd 0. Consider using --shell-job option. | (00.012929) Error (tty.c:1022): tty: Found dangling tty with sid 940 pgid 2621 (pts) on peer fd 0. Consider using --shell-job option. | ||
(00.013111) Error (cr-dump.c:1636): Dumping FAILED. | (00.013111) Error (cr-dump.c:1636): Dumping FAILED. | ||
− | See, | + | See, criu asks to set the <code>--shell-job</code>, because we try to dump only a part of a session and a slave end of a tty pair. It is a common rule to ask a user, if only a part of something is dumped. |
− | # | + | # criu dump -vvvv -o dump.log -t 2621 --shell-job && echo OK |
OK | OK | ||
=== Restore === | === Restore === | ||
− | + | # criu restore -vvvv -o restore.log -t 2621 --shell-job | |
Fri Apr 12 12:41:09 MSK 2013 | Fri Apr 12 12:41:09 MSK 2013 | ||
Fri Apr 12 12:41:10 MSK 2013 | Fri Apr 12 12:41:10 MSK 2013 | ||
[[Category:HOWTO]] | [[Category:HOWTO]] |
Revision as of 17:06, 30 April 2013
This HOWTO describes how to dump a trivial program.
Simplest case
Prepare
Let's create a shell script which loops and reports time every second:
$ cat > test.sh <<-EOF #!/bin/sh while :; do sleep 1 date done EOF $ chmod +x test.sh
Run (isolated)
Now, if you try to simply run and try to dump such a program, criu will fail. The reason is a program you launch from the shell shares some common resources with the shell, notably its session and terminal. Criu has a built-in check that makes sure there are no such resources.
To remove the dependency on a current terminal, let's executed our script in a new session and redirect its output to a file:
$ setsid ./test.sh < /dev/null &> test.log & [2] 2220 [2]+ Done setsid ./test.sh < /dev/null &>test.log
Dump
Get the PID of the test process:
$ ps -C test.sh PID TTY TIME CMD 2221 ? 00:00:00 test.sh
Dump it:
# criu dump -t 2221 -vvv -o dump.log && echo OK OK
Check dump files
The state of the process(es) is saved to a few files:
$ ls core-2221.img eventpoll-tfd.img filelocks-2221.img inotify.img netlinksk.img pipes.img sigacts-2424.img test.log core-2424.img fanotify.img filelocks-2424.img inotify-wd.img packetsk.img pstree.img signalfd.img test.sh creds-2221.img fanotify-mark.img fs-2221.img inventory.img pagemap-2221.img reg-files.img signal-p-2221.img tty.img creds-2424.img fdinfo-2.img fs-2424.img itimers-2221.img pagemap-2424.img remap-fpath.img signal-p-2424.img tty-info.img dump.log fdinfo-3.img ids-2221.img itimers-2424.img pages-1.img rlimit-2221.img signal-s-2221.img unixsk.img eventfd.img fifo-data.img ids-2424.img mm-2221.img pages-2.img rlimit-2424.img signal-s-2424.img vmas-2221.img eventpoll.img fifo.img inetsk.img mm-2424.img pipes-data.img sigacts-2221.img sk-queues.img vmas-2424.img
Restore
Restore the test process:
# criu restore -d -t 2221 -vvv -o restore.log && echo OK OK
A shell job
Now let's see how to dump the same program when it is just started from the shell without any additional setsid and stdio redirection. For that we need to execute our test script or another program (e.g. "top") from a terminal without any redirection.
Note criu only supports Unix98 PTYs.
Run
$ ./test.sh $ ps -C test.sh PID TTY TIME CMD 2621 pts/1 00:00:00 test.sh
Dump
Currently criu doesn't support a stopped task, so "criu dump" must be executed from another terminal.
# criu dump -t 2621 (00.012929) Error (tty.c:1022): tty: Found dangling tty with sid 940 pgid 2621 (pts) on peer fd 0. Consider using --shell-job option. (00.013111) Error (cr-dump.c:1636): Dumping FAILED.
See, criu asks to set the --shell-job
, because we try to dump only a part of a session and a slave end of a tty pair. It is a common rule to ask a user, if only a part of something is dumped.
# criu dump -vvvv -o dump.log -t 2621 --shell-job && echo OK OK
Restore
# criu restore -vvvv -o restore.log -t 2621 --shell-job Fri Apr 12 12:41:09 MSK 2013 Fri Apr 12 12:41:10 MSK 2013