<?xml version="1.0" encoding="UTF-8" ?>
<rss version="0.91">
  <channel>
    <title>プログラムネタ帳</title>
    <description>プログラムの自分に必要なネタを残しています。</description>
    <link>https://seikenzuki.blog.shinobi.jp/</link>
    <language>ja</language>
    <copyright>Copyright (C) NINJATOOLS ALL RIGHTS RESERVED.</copyright>

    <item>
      <title>DOSプロンプトでコマンドの別名を使用する。(doskey)</title>
      <description>■ DOSプロンプトでコマンドの別名を使用する。(doskey)&lt;br /&gt;
DOSプロンプトでコマンドの別名を定義するにはdoskeyコマンドを使用する。&lt;br /&gt;
&lt;pre style=&quot;background-color: #000000; color: #ffffff&quot;&gt;doskey l=dir /b $*&lt;br /&gt;
doskey ll=dir $*&lt;br /&gt;
&lt;/pre&gt;※S* は引数を受け取る部分&lt;br /&gt;
&lt;br /&gt;
■ 定義の自動実行&lt;br /&gt;
doskeyコマンドの定義は、毎回設定しなくていいように自動実行されるバッチファイルに定義するとよい。&lt;br /&gt;
&lt;br /&gt;
自動実行されるバッチファイルは以下のレジストリに設定する&lt;br /&gt;
&lt;br /&gt;
マシン全体の設定　HKEY_LOCAL_MACHINE/Software/Microsoft/Command Processor/AutoRun&lt;br /&gt;
ユーザーごとの設定　HKEY_CURRENT_USER/Software/Microsoft/Command Processor/AutoRun&lt;br /&gt;
※両方に同じバッチファイルを設定すると、２回起動される。&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.seikenzuki.blog.shinobi.jp/20120105_001.png&quot; alt=&quot;図１．マシン全体の設定にc:/bin/autorun.batを設定した場合。&quot;/&gt;&lt;br /&gt;
図１．マシン全体の設定にc:/bin/autorun.batを設定した場合。&lt;br /&gt;
&lt;br /&gt;
レジストリエディタの起動は「ファイル名を指定して実行」から「regedit」と入力、&lt;br /&gt;
もしくは以下のファイルいずれかをダウンロードして実行するとレジストリが登録されます。&lt;br /&gt;
自動実行レジストリ設定ファイル（マシン）&lt;a href=&quot;http://file.seikenzuki.blog.shinobi.jp/AutoRun_LOCAL_MACHINE.reg&quot; target=&quot;_blank&quot;&gt;ダウンロード&lt;/a&gt;&lt;br /&gt;
自動実行レジストリ設定ファイル（ユーザー）&lt;a href=&quot;http://file.seikenzuki.blog.shinobi.jp/AutoRun_CURRENT_USER.reg&quot; target=&quot;_blank&quot;&gt;ダウンロード&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
■ c:/bin/autorun.batの内容&lt;br /&gt;
&lt;pre style=&quot;background-color: #000000; color: #ffffff&quot;&gt;@echo off&lt;br /&gt;
doskey l=dir /b $*&lt;br /&gt;
doskey ll=dir $*&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
自動実行バッチ &lt;a href=&quot;http://file.seikenzuki.blog.shinobi.jp/autorun.bat&quot; target=&quot;_blank&quot;&gt;ダウンロード&lt;/a&gt;&lt;br /&gt;
</description> 
      <link>https://seikenzuki.blog.shinobi.jp/dos/dos%E3%83%97%E3%83%AD%E3%83%B3%E3%83%97%E3%83%88%E3%81%A7%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AE%E5%88%A5%E5%90%8D%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%E3%80%82-doskey-</link> 
    </item>
    <item>
      <title>alias コマンドの別名を登録する</title>
      <description>alias コマンドの別名を登録する&lt;br&gt;
&lt;br&gt;
&lt;table&gt;
 &lt;tr&gt;&lt;td&gt;alias&lt;/td&gt;&lt;td&gt;別名の一覧を表示する&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;alias l='ls'&lt;/td&gt;&lt;td&gt;lsコマンドの別名としてlを登録する&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;alias ll='ls -la'&lt;/td&gt;&lt;td&gt;ls-laコマンドの別名としてllを登録する&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;pre&gt;hoge@ubuntu:~$ l
l: command not found
hoge@ubuntu:~$ ll
ll: command not found
hoge@ubuntu:~$ alias
hoge@ubuntu:~$ alias l='ls'
hoge@ubuntu:~$ alias ll='ls -la'
hoge@ubuntu:~$ l
public_html
hoge@ubuntu:~$ ll
total 40
drwxr-xr-x 6 hoge hoge 4096 2011-10-26 01:19 .
drwxr-xr-x 4 root root 4096 2011-09-16 03:26 ..
drwx------ 2 hoge hoge 4096 2011-10-14 06:06 .aptitude
-rw------- 1 hoge hoge 5918 2011-12-16 08:07 .bash_history
drwx------ 2 hoge hoge 4096 2011-09-16 03:37 .cache
-rw------- 1 hoge hoge    3 2011-09-16 06:11 .psql_history
drwxr-xr-x 4 hoge hoge 4096 2011-11-18 01:42 public_html
drwx------ 2 hoge hoge 4096 2011-09-16 03:37 .ssh
-rw------- 1 root root 1580 2011-09-16 06:09 .viminfo
hoge@ubuntu:~$ alias
alias l='ls'
alias ll='ls -la'
hoge@ubuntu:~$&lt;/pre&gt;
&lt;br&gt;
このままではログイン時に毎回aliasを設定する必要があるので、&lt;br&gt;

.bashrcにaliasコマンドを登録して置く。&lt;br&gt;
&lt;br&gt;
hogeユーザーでログインしているため、&lt;br&gt;
以下の内容で/home/hoge/.bashrcを作成する。&lt;br&gt;
■/home/hoge/.bashrc
&lt;pre&gt;alias l='ls'
alias ll='ls -la'&lt;/pre&gt;
/home/hoge/.bashrcを作成したら、「source .bashrc」コマンドで適用するか&lt;br&gt;
一旦ログアウトして再度ログインすると、aliasで登録したコマンドが使えるようになる。
</description> 
      <link>https://seikenzuki.blog.shinobi.jp/linux/alias%20%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AE%E5%88%A5%E5%90%8D%E3%82%92%E7%99%BB%E9%8C%B2%E3%81%99%E3%82%8B</link> 
    </item>
    <item>
      <title>ps プロセスの一覧を表示する、kill プロセスを終了する。</title>
      <description>&lt;pre class=&quot;normal&quot;&gt;・ps -alx
　よく使われるpsコマンドのオプション

■psコマンドのオプション
a  自分以外のユーザーのプロセスも表示する
c  task_structに格納されているコマンド名を表示する
e  「実行命令 + 」に環境変数を付加する
f  ツリー形式で表示する
h  ヘッダーを表示しない
j  pgidとsidを表示する
l  標準のPID，TTY，TIME，CMDに加え，F，S，UID，PPID，C，PRI，NI，ADDR，SZ，VSZ，RSS，WCHAN，STATも表示する
m  スレッドも表示する
n  USERとWCHANを数字で表示する
r  実行中のプロセスだけ表示する
s  シグナル形式で表示する
u  ユーザー名と開始時刻を表示する
v  vm 形式で表示する
w  １行追加して表示を拡大する。wを増やすことによって行数をさらに増やせる
x  制御端末のないプロセスの情報も表示する
S  子プロセスのCPU消費時間とページ・フォルトを合計する
txx  tty xxのプロセスのみ表示する
pids  表示するプロセスIDを指定する&lt;/pre&gt;
&lt;br&gt;
実行結果&lt;br&gt;
&lt;pre&gt;hoge@ubuntu:~$ ps -alx
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0     1     0  20   0   2916  1712 poll_s Ss   ?          0:01 /sbin/init
1     0     2     0  20   0      0     0 kthrea S    ?          0:00 [kthreadd]
1     0     3     2  20   0      0     0 run_ks S    ?          0:00 [ksoftirqd/0]
5     0     5     2  20   0      0     0 worker S    ?          0:00 [kworker/u:0]
1     0     6     2 -100  -      0     0 cpu_st S    ?          0:00 [migration/0]
1     0     7     2   0 -20      0     0 rescue S&amp;lt;   ?          0:00 [cpuset]
1     0     8     2   0 -20      0     0 rescue S&amp;lt;   ?          0:00 [khelper]
1     0     9     2   0 -20      0     0 rescue S&amp;lt;   ?          0:00 [netns]
1     0    10     2  20   0      0     0 bdi_sy S    ?          0:00 [sync_supers]
1     0    11     2  20   0      0     0 bdi_fo S    ?          0:00 [bdi-default]

...中略...

4     0   725     1  20   0   5652  2260 poll_s Ss   ?          0:00 /usr/sbin/sshd -D
4     0   737     1  20   0   3864   968 inet_c Ss   ?          0:00 /usr/sbin/vsftpd
1     0   746     2  20   0      0     0 bdi_wr S    ?          0:00 [flush-251:0]
1   105   749   687  20   0  46116  1336 poll_s Ss   ?          0:00 postgres: writer proc
1   105   750   687  20   0  46116  1112 poll_s Ss   ?          0:00 postgres: wal writer
1   105   751   687  20   0  46252  1508 poll_s Ss   ?          0:00 postgres: autovacuum
1   105   752   687  20   0  14428  1220 poll_s Ss   ?          0:00 postgres: stats colle
0     0   814     1  20   0   1872   580 n_tty_ Ss+  tty1       0:00 /sbin/getty -8 38400
4     0   817   725  20   0   8580  2848 unix_s Ss   ?          0:00 sshd: hoge [priv]
5  1001   837   817  20   0   8580  1568 poll_s S    ?          0:00 sshd: hoge@pts/0
0  1001   838   837  20   0   6292  3552 n_tty_ Ss+  pts/0      0:00 -bash
4     0   895   725  20   0   8580  2848 unix_s Ss   ?          0:00 sshd: hoge [priv]
5  1001   920   895  20   0   8580  1568 poll_s S    ?          0:00 sshd: hoge@pts/1
0  1001   921   920  20   0   6292  3552 wait   Ss   pts/1      0:00 -bash
0  1001   983   921  20   0   3940   996 -      R+   pts/1      0:00 ps -alx
hoge@ubuntu:~$&lt;/pre&gt;

&lt;pre class=&quot;normal&quot;&gt;
RSSはメモリの使用量を見るのに使われる。
PIDは特定のプロセスを切るために、UIDはユーザーIDで、/etc/passwdファイルを参照すると、ユーザー名を確認することができる。

■ユーザー名確認&lt;/pre&gt;

&lt;pre&gt;hoge@ubuntu:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
syslog:x:101:103::/home/syslog:/bin/false
landscape:x:102:108::/var/lib/landscape:/bin/false
notroot:x:1000:1000:notroot,,,:/home/notroot:/bin/bash
hoge:x:1001:1001::/home/hoge:/bin/bash
sshd:x:103:65534::/var/run/sshd:/usr/sbin/nologin
ftp:x:104:112:ftp daemon,,,:/srv/ftp:/bin/false
postgres:x:105:114:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
hoge@ubuntu:~$&lt;/pre&gt;

&lt;pre class=&quot;normal&quot;&gt;
プロセスはkillコマンドで終了できる。
kill -9 pid　この構文で指定したプロセスを強制終了する。
kill -1 pid　-1とすると、プロセスを再起動させる。
ps -alxの結果から、ユーザIDとCOMMANDを頼りに強制終了するプロセスを絞込むといい気がする。

■プロセスを強制終了&lt;/pre&gt;

&lt;pre&gt;hoge@ubuntu:~$ kill -9 921
hoge@ubuntu:~$ ps -alx
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0     1     0  20   0   2916  1712 poll_s Ss   ?          0:01 /sbin/init
1     0     2     0  20   0      0     0 kthrea S    ?          0:00 [kthreadd]
1     0     3     2  20   0      0     0 run_ks S    ?          0:00 [ksoftirqd/0]
5     0     5     2  20   0      0     0 worker S    ?          0:00 [kworker/u:0]
1     0     6     2 -100  -      0     0 cpu_st S    ?          0:00 [migration/0]
1     0     7     2   0 -20      0     0 rescue S&lt;   ?          0:00 [cpuset]
1     0     8     2   0 -20      0     0 rescue S&lt;   ?          0:00 [khelper]
1     0     9     2   0 -20      0     0 rescue S&lt;   ?          0:00 [netns]
1     0    10     2  20   0      0     0 bdi_sy S    ?          0:00 [sync_supers]
1     0    11     2  20   0      0     0 bdi_fo S    ?          0:00 [bdi-default]

...中略...

4     0   725     1  20   0   5652  2260 poll_s Ss   ?          0:00 /usr/sbin/sshd -D
4     0   737     1  20   0   3864   968 inet_c Ss   ?          0:00 /usr/sbin/vsftpd
1     0   746     2  20   0      0     0 bdi_wr S    ?          0:00 [flush-251:0]
1   105   749   687  20   0  46116  1336 poll_s Ss   ?          0:00 postgres: writer process
1   105   750   687  20   0  46116  1112 poll_s Ss   ?          0:00 postgres: wal writer process
1   105   751   687  20   0  46252  1508 poll_s Ss   ?          0:00 postgres: autovacuum launcher process
1   105   752   687  20   0  14428  1220 poll_s Ss   ?          0:00 postgres: stats collector process
0     0   814     1  20   0   1872   580 n_tty_ Ss+  tty1       0:00 /sbin/getty -8 38400 tty1
4     0   817   725  20   0   8580  2848 unix_s Ss   ?          0:00 sshd: hoge [priv]
5  1001   837   817  20   0   8580  1568 poll_s S    ?          0:00 sshd: hoge@pts/0
0  1001   838   837  20   0   6344  3640 wait   Ss   pts/0      0:00 -bash
0  1001  1074   838  20   0   3940   992 -      R+   pts/0      0:00 ps -alx
hoge@ubuntu:~$&lt;/pre&gt;

&lt;pre class=&quot;normal&quot;&gt;ターミナルを2枚開いていたため、1001:hogeユーザーの-bashが2つ表示されていたが、
killコマンドで強制終了したため、1つになった。
※ターミナルも切断される。&lt;/pre&gt;</description> 
      <link>https://seikenzuki.blog.shinobi.jp/linux/ps%20%E3%83%97%E3%83%AD%E3%82%BB%E3%82%B9%E3%81%AE%E4%B8%80%E8%A6%A7%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B%E3%80%81kill%20%E3%83%97%E3%83%AD%E3%82%BB%E3%82%B9%E3%82%92%E7%B5%82%E4%BA%86%E3%81%99%E3%82%8B%E3%80%82</link> 
    </item>
    <item>
      <title>テスト</title>
      <description>テスト</description> 
      <link>https://seikenzuki.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%83%86%E3%82%B9%E3%83%88</link> 
    </item>

  </channel>
</rss>