в чем разница между поиском и пропуском в команде dd?

На основе программы memdump , первоначально найденной здесь , я создал сценарий для выборочного чтения указанных приложений обратно в память. запомните :

#!/bin/bash
declare -A Q
for i in "$@"; do
    E=$(readlink /proc/$i/exe);
    if [ -z "$E" ]; then.
        #echo skipped $i;.
        continue;.
    fi
    if echo $E | grep -qF memdump; then.
        #echo skipped $i >&2;.
        continue;.
    fi
    if [ -n "${Q[${E}]}" ]; then.
        #echo already $i >&2;.
        continue;.
    fi
    echo "$i $E" >&2
    memdump $i 2> /dev/null
    Q[$E]=$i
done | pv -c -i 2 > /dev/null

Использование: что-то вроде

# ./remember $(< /mnt/cgroup/tasks )
1 /sbin/init
882 /bin/bash
1301 /usr/bin/hexchat
...
2.21GiB 0:00:02 [ 1.1GiB/s] [  <=>     ]
...
6838 /sbin/agetty
11.6GiB 0:00:10 [1.16GiB/s] [      <=> ]
...
23.7GiB 0:00:38 [ 637MiB/s] [   <=>    ]
# 

Он быстро пропускает память без подкачки (гигабайт в секунду) и замедляется, когда требуется подкачка.

6
01.09.2016, 13:23
1 ответ

Следующий пример сначала подготавливает входной файл и выходной файл, а затем копирует часть ввода в часть выходного файла.

echo     "IGNORE:My Dear Friend:IGNORE"      > infile
echo "Keep this, OVERWRITE THIS, keep this." > outfile
cat infile
cat outfile
echo
dd status=none \
   bs=1 \
   if=infile \
   skip=7 \
   count=14 \
   of=outfile \
   conv=notrunc \
   seek=11

cat outfile

Аргументы dd::

status=none  Don't output final statistics as dd usually does - would disturb the demo
bs=1         All the following numbers are counts of bytes -- i.e., 1-byte blocks.
if=infile    The input file
skip=7       Ignore the first 7 bytes of input (skip "IGNORE:")
count=14     Transfer 14 bytes from input to output
of=outfile   What file to write into
conv=notrunc Don't delete old contents of the output file before writing.
seek=11      Don't overwrite the first 11 bytes of the output file
             i.e., leave them in place and start writing after them

Результат выполнения скрипта::

IGNORE:My Dear Friend:IGNORE
Keep this, OVERWRITE THIS, keep this.

Keep this, My Dear Friend, keep this.

Что произойдет, если вы поменяете местами значения «пропустить» и «искать»? dd скопирует неправильную часть входных данных и перезапишет неправильную часть выходного файла:

Keep thear Friend:IGNTHIS, keep this.
7
27.01.2020, 20:20

Теги

Похожие вопросы