Changes

Jump to navigation Jump to search
435 bytes added ,  03:51, 13 December 2018
m
→‎Dump: Add a single line tip
Line 1: Line 1: −
= Dumping a simplest process in a new session without controll terminal =
+
This HOWTO describes how to dump a trivial program.
At first let's dump/restore a trivial process without external dependences.
+
 
* For that we can create a shell script, which will report date and time every second. For removing dependences on a current terminal it will be executed in a new session and output will be redirected in a file.
+
== Simplest case ==
 +
 
 +
=== Prepare ===
 +
 
 +
Let's create a shell script which loops and reports time every second:
 +
 
 
  $ cat > test.sh <<-EOF
 
  $ cat > test.sh <<-EOF
 
  #!/bin/sh
 
  #!/bin/sh
Line 9: Line 14:  
  done
 
  done
 
  EOF
 
  EOF
   
  $ chmod +x test.sh
 
  $ 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 &
 
  $ setsid ./test.sh  < /dev/null &> test.log &
 
  [2] 2220
 
  [2] 2220
 
  [2]+  Done                    setsid ./test.sh < /dev/null &>test.log
 
  [2]+  Done                    setsid ./test.sh < /dev/null &>test.log
   −
* Get pid of the test process:
+
=== Dump ===
 +
 
 +
Get the PID of the test process:
 +
 
 
  $  ps -C test.sh
 
  $  ps -C test.sh
 
   PID TTY          TIME CMD
 
   PID TTY          TIME CMD
 
  2221 ?        00:00:00 test.sh
 
  2221 ?        00:00:00 test.sh
* Dump the test process.
+
 
  $  ~/crtools/crtools dump -t 2221 -vvv -o dump.log && echo OK
+
Dump it:
 +
 
 +
  # criu dump -t 2221 -vvv -o dump.log && echo OK
 
  OK
 
  OK
* The state of the processes are saved in a few files:
+
 
 +
'''Tip:''' Alternatively, you can combine both steps into a single command: <code># criu dump -t $(pgrep test.sh) -v4 -o dump.log</code>
 +
 
 +
=== Check dump files ===
 +
 
 +
The state of the process(es) is saved to a few files:
 +
 
 
  $  ls
 
  $  ls
 
  core-2221.img  eventpoll-tfd.img  filelocks-2221.img  inotify.img      netlinksk.img    pipes.img        sigacts-2424.img  test.log
 
  core-2221.img  eventpoll-tfd.img  filelocks-2221.img  inotify.img      netlinksk.img    pipes.img        sigacts-2424.img  test.log
Line 31: Line 53:  
  eventfd.img    fifo-data.img      ids-2424.img        mm-2221.img      pages-2.img      rlimit-2424.img  signal-s-2424.img  vmas-2221.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
 
  eventpoll.img  fifo.img          inetsk.img          mm-2424.img      pipes-data.img    sigacts-2221.img  sk-queues.img      vmas-2424.img
* Restore the test process.
+
 
  $ ~/crtools/crtools restore -d -t 2221 -vvv -o restore.log && echo OK
+
=== Restore ===
 +
 
 +
Restore the test process:
 +
 
 +
  # criu restore -d -vvv -o restore.log && echo OK
 
  OK
 
  OK
   −
= Dumping one shell job =
+
== A shell job ==
Now let's try to dump a program, which is using a terminal. For that we need to execute our test script or another program (e.g. "top") from a terminal without redirections. It will report date and time every second. crtools supports only [http://en.wikipedia.org/wiki/Pseudo_terminal Unix98 PTYs].
+
 
 +
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 [http://en.wikipedia.org/wiki/Pseudo_terminal Unix98 PTYs].
 +
 
 +
=== Run ===
 +
 
 
  $ ./test.sh
 
  $ ./test.sh
 
  $ ps -C test.sh
 
  $ ps -C test.sh
Line 42: Line 75:  
   2621 pts/1    00:00:00 test.sh
 
   2621 pts/1    00:00:00 test.sh
   −
Currently crtools doesn't support a stopped task, so "crtools dump" must be executed from another terminal.
+
=== Dump ===
  $  ~/crtools/crtools dump -t 2621
+
 
 +
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.
crtools asks to set the option --shell-job, because we try to dump only a part of session and a slave point of a tty pair. It's a common rule to ask a user, if only a part of something is dumped.
+
 
  $ ~/crtools/crtools dump -vvvv -o dump.log -t 2621 --shell-job && echo Ok
+
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.
  Ok
+
 
  $ ~/crtools/crtools restore -vvvv -o restore.log -t 2621 --shell-job
+
  # criu dump -vvvv -o dump.log -t 2621 --shell-job && echo OK
 +
  OK
 +
 
 +
=== Restore ===
 +
 
 +
  # criu restore -vvvv -o restore.log --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]]
277

edits

Navigation menu