1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SadServers学習メモ #1】使ったコマンドまとめ(lsof, kill)

Posted at

初めに

Linuxの学習目的でSadServersを始めました。
備忘のために使用したコマンドをアウトプットします。

SadServersとは

Linuxの学習ができるサイト。
架空のサーバを題材とし与えられた依頼をこなすことで学習ができる。

今回のお題

タイトル

"Saint John": what is writing to this log file?"

詳細

  • /var/log/bad.logにログが出力され続けているので、それを止めてほしい
出力され続けるログ
$ tail -F /var/log/bad.log 
2025-04-29 01:15:03.730473 token: 825025757
2025-04-29 01:15:04.030921 token: 1946086412
2025-04-29 01:15:04.331377 token: 841718178
2025-04-29 01:15:04.631844 token: 2070521251
2025-04-29 01:15:04.932360 token: 2083434091
2025-04-29 01:15:05.232844 token: 1728017062
2025-04-29 01:15:05.533384 token: 1271143929
2025-04-29 01:15:05.833867 token: 1444703944
2025-04-29 01:15:06.134343 token: 284394902
2025-04-29 01:15:06.434799 token: 1370351268
2025-04-29 01:15:06.735259 token: 1626528688

作業の流れ

  • /var/log/bad.logを出力しているプロセスを特定する
  • 特定したプロセスをキルする

使ったコマンド

lsof

あるプロセスが握っているファイルを特定することができるコマンド。
ファイルのパスを指定することで、プロセスを特定することもできる。

このコマンドで、プロセスのPIDが591だと分かった。

lsofコマンド
$ lsof /var/log/bad.log 
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
badlog.py 591 admin    3w   REG  259,1    10179 265802 /var/log/bad.log

kill

プロセスを停止するコマンド。

先ほど調べたプロセスのPIDを指定し、プロセスを停止する。

killコマンド
$ kill 591

終わりに

Linuxをどうやって勉強しようか悩んでいましたが、SadServersは実際に手を動かしながら学習できるので力が付きそうです。今後も継続して実施していきます。

ここまでご覧いただきありがとうございました!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?