はじめに 本記事は電子書籍版もあります。 linuxカーネルはC言語のマクロを駆使して書かれています。それらのうち、凝ったマクロになじみの無い人には初見では意図がわからない&わかってみれば面白いであろうものをいくつか紹介いたします。対象読者は、C言語のユーザだけれども、マクロは定数定義くらいにしか使わないというライトなマクロユーザです。 マクロを使用する場所に依存するエラーを防ぐ 次のマクロは、二つの引き数の値を置換するだけの単純なものです。
関連記事 共同プロジェクトも展開:Red Hat、Linuxコンテナ技術で米新興企業と提携 米Red Hatは、Linuxの次世代コンテナ技術に関して、米新興企業と提携を結んだと発表した。Red Hat Enterprise Linuxに「Docker」を組み合わせて、Red HatのPaaS製品の強化を目指す。 認定ホスト間でのシームレスな機能を保証:米レッドハット、コンテナー化されたアプリケーションの認定プログラムを発表 米レッドハットは2014年3月11日、コンテナー化されたアプリケーションの認定プログラム「Red Hat Container Certification」を発表した。既存のアプリケーション認定プログラムの延長だ。 ユーザーは「PaaS」「IaaS」を求めているわけではない:狭義の「PaaS」を超えようとするレッドハットのOpenShift レッドハットは、PaaS製品
ネットワークが絡んだ通信プログラムを開発していると、テストのために遅延やパケロスを意図的に発生させたくなることがあります。いまどきは IDE にネットワークエミュレーション機能が組み込まれていたり、仮想環境で容易に再現できたりもしますが、箱物のネットワークエミュレータがあるとネットワークの構成を気にせずカンタンに設置できるのですごく便利だったりします。世の中にはそういった製品が沢山あるので安価なものを買ってもいいのですが、新たにラズパイが届いたばかりだったので、これを使って超小型のネットワークエミュレータを自作してみました。前編と後編の二回に分けて紹介します。 最近、社内で「ラズパイおじさん」と呼ばれるようになりました。@pandax381 です。 ラズパイ + Linux = ネットワークエミュレータ 「ネットワークエミュレータを自作」と言うとなんだか凄そうな感じがしますが、実はものすご
カーネルセットアップの第一歩 前回の パート では、Linuxカーネルの内部について探り始め、カーネルをセットアップするコードの最初の部分を見ていきました。前回の投稿は arch/x86/boot/main.c 内の main 関数(C言語で書かれた最初の関数)を呼び出すところまで確認しました。 このパートでは、引き続きカーネルのセットアップコードについて調査し、併せて以下の内容も学びます。 protected mode (プロテクトモード)の概要 * プロテクトモードに移行するための準備 ヒープとコンソールの初期化 メモリの検出、CPUの検証、キーボードの初期化 その他もろもろ それでは始めていきましょう。 プロテクトモード ネイティブのIntel64の ロングモード に移行する前に、カーネルはCPUをプロテクトモードに切り替える必要があります。 では、この プロテクトモード とは何でし
何千人ものプレイヤーがコマンドを送信して「ポケモン」や「ダークソウル」をクリアするTwitchの名物企画に、今度はみんなでLinuxをインストールする実況チャンネル「Twitch Installs Arch Linux」が登場し、みんなでコマンドを入力しまくるお祭り状態になっています。 Twitch Installs Arch Linux https://www.twitchinstalls.com/ Linuxをインストールする実況チャンネル「TwitchInstallsArchLinux」は以下のURLから視聴することが可能です。 TwitchInstallsArchLinux - Twitch http://www.twitch.tv/twitchinstallsarchlinux Twitch Installs Arch Linuxは、生配信を視聴しているユーザーが入力したコマンド
LinuxプロセスのCopy on Writeによるメモリ共有率を計算するプログラム。 こちらのエントリーと Linux のプロセスが Copy on Write で共有しているメモリのサイズを調べる 上記エントリー内で参照されている Perl:forkしたプロセス間でのメモリ領域の共有 を参考にして、紹介されている Linux::Smaps モジュールを利用したPerlのプログラムをPythonで書いてみました。外部モジュールのインストールなしで動作するので使いやすいかと思います。Python 2.6系以上で動作することを確認しています。 #!/usr/bin/env python import sys def read_smaps(pidlist): try: print("PID\tRSS\tSHARED\t\tNONE_SHARED") mem = lambda t, f: int
Linux Kernel 2.6 (x86-64) でのページテーブルのサイズの確認方法と見積式を調べてみた。 あっているか自信のないところもある&まだ書きかけ。 ページテーブルのサイズの見方 OS全体のページテーブルのサイズ $ cat /proc/meminfo MemTotal: 16158544 kB MemFree: 13134056 kB (中略) PageTables: 34428 kB ★ 34MB プロセス毎のページテーブルのサイズ $ cat /proc/10225/status # 10255 は PID Name: zsh State: S (sleeping) Tgid: 10225 Pid: 10225 PPid: 10222 (中略) VmPTE: 124 kB ★ 124KB ページテーブルのサイズの見積式 見積式 (プロセスが使用している物理メモリサイズ
しばらく、LinuxやらMacのターミナル触ってると、こんなことを感じる人も多いのでは。 「cdやらrmやら、基本的な事はできるようになったなぁ。でも、あと、なにができるんやろ?」 この本読めばわかりますよ。ホイサッサ。そして、Linux世界感が広がります。 本書を手にとったきっかけ Linux、今までも、なんとなくは触る機会があった。仕事ではAmazon Linuxを2年ほど使っていたし、このブログもさくらのVPS上のCent OSで動いているし、まぁ最低限の使い方は知っていたわけなんですよね。 Macも元はBSD UNIXベースなだけあって、何気にUnix、Linux環境はそこらへんに存在している。 ただ、最近入った現場が、あろうことか、「ネットに繋げない」という、もう自分にとっては窒息して死んでしまいそうな環境だったんですよ。 日々の仕事においても、コマンドの使い方を調べるのにも一苦
LinuxやUNIXで、コマンドちょっと組み合わせて利用する際、非常に役に立つxargsコマンド。 今回は、このxargsコマンドで覚えておきたい使い方・組み合わせについて紹介する。 1.基本的な使い方 まず、そもそもこのコマンドはどういう使い方をするのか。 基本的には、以下のようにパイプでつなぐことで前のコマンド(コマンド1)で取得した値(標準出力)を利用してxargsで指定した別のコマンド(コマンド2)に引数として渡して実行させる事ができるコマンドだ。 コマンド1 | xargs コマンド2 [root@test-centos7 ~]# find /work -type f /work/test2.txt /work/test.txt /work/aaaaa.txt /work/bbbbb.txt /work/ccccc.txt /work/ddddd.txt /work/sample
追記が増えたので整理 経緯 2.5GBのテキストファイルを加工する必要があり、①vimで開いて加工→vim死亡②sublime textで開いて加工→sublime text死亡となったため、awkを用いて以下の様なコマンドを実行した。 $ cat sample.txt | awk '$5 ~ /((26|27|28|29|30)\/Jun|(01|02|03)\/Jul)/{ print }' > result.txt すると 「catいらなくね?」と指摘 さらにMATSUMOTO, Ryosuke (@matsumotory) | Twitter < 「キャッシュに入れて高速化してるんかと思った」 とコメントをもらいました。ので、どっちが速いかの検証です。 注意 加工の目的はログファイルからある期間だけの行を抜き取りたい 正規表現がいけてないのは気にしない 比較 awkにファイル指定す
LinuxやUNIXを利用していると、スクリプト名などのファイル名のルールが変更したため、一括で置換を行いたいときがある。 そんな時は、どうすればいいのだろうか? 1.『rename』コマンドを利用する もし『rename』コマンドがあるようならば、これを利用するといいだろう。 Linuxには大体最初から用意されている。(なお、Ubuntuの場合だと置換の指定方法がPerl(sed)の指定方法になっている) rename 置換する単語 置換後の単語 対象PATH この対象PATHにはワイルドカードも利用できるので、以下のように一括で置換を行える。 [root@test-centos7 test]# ls -l 合計 0 -rw-r--r--. 1 root root 0 7月 3 06:37 TCScript0.sh -rw-r--r--. 1 root root 0 7月 3 06:37
yumやapt-getからインストールしたり、rpmやdebパッケージを利用してインストールした場合、アンインストールやアップグレードを行うのは簡単だ。 しかし、ソースファイルからコンパイルしたパッケージの場合、makeファイルにuninstallが用意されているならまだしも、もし用意されてないと、パッケージをアンインストールしたりするのは非常に大変だ。 そんなソースからコンパイルしmake installしたパッケージを管理してくれるのが、『porg』だ。pacoという、同じくソースからインストールしたパッケージの管理ツールが前身。 今回は、この『porg』をCentOS 7に実際にインストールし、ソースからインストールしたパッケージを管理してみることにする。 1.『porg』のインストール まずは『porg』のインストールから。 以下のコマンドを実行し、パッケージのソースコードをダウン
課題 /tmpと/var/tmpどっちも大体一緒だからいいんじゃないかと思って/tmpにファイルをつくろうとしたら、プログラムが使用するものは/var/tmpにと叱られた。確かに、基幹系システムのディストリビューションだと何故か/var/tmp派の人が多かった気がする。じゃあ、linux系特有の宗派の問題なのか?と思い調べてみた。 何が他のディレクトリと違うか 通常のディレクトリは、基本的にはファイルは削除しない限り消えない。 /tmpに関しては再起動するとファイルが綺麗さっぱり無くなる。 /var/tmpは再起動しても消えないがいつの間にかファイルが消えることがある。 うーん、やはり使用してきたディストリビューションのルールか、業務の慣例的なルールなのかなぁ。 やはり/tmpと/var/tmpは宗教論争なの? そういうわけではないらしい。FHS(Filesystem Hierarchy
LPI-Japan、「Linuxシステム管理標準教科書」を公開、無償での配布を開始 ~現場で求められるLinuxのシステム管理に必要なスキル習得のために最適な教科書 ~ ITプロフェッショナル認定機関として「LPIC」、「OSS-DB技術者認定試験」、「HTML5プロフェッショナル認定試験」、「Apache CloudStack技術者認定試験」を実施する特定非営利活動法人エルピーアイジャパン(以下:LPI-Japan、東京都港区、理事長 成井 弦、https://www.lpi.or.jp )は、OSS/Linuxの技術者育成・教育のための教材「Linuxシステム管理標準教科書」を本日公開したことを発表しました。 本教材は、 PDF版、EPUB版、Kindle版、書籍版での提供となり、PDF版とEPUB版は6月1日(月)より、LPI-JapanのWebサイト( https://www.lp
特定のホストへのルートを確認するコマンドといえば、tracerouteコマンドだ。 今回は、そんなtracerouteコマンドで覚えておきたい使い方についてまとめてみる事にした。 1.基本的な使い方 tracerouteコマンドは、基本的には以下のように実行し、そのホストに至るまでの経路(どこのルーターを通っているか等)を確認出来る。 デフォルトでは、UDPプロトコルを利用して通信確認を行う。 traceroute 対象ホスト(ホスト名・IPアドレス) tracerouteコマンドでは、対象のホストに向けてTTLを1づつ足して通信確認を行っている。 そのため、通信の途中で傷害が発生していたとしても、どこの経路で発生しているのかがわかるようになっている。 動作のより詳しい解説については、こちらのサイトが記述してくれている。 2.使用するプロトコル・ポートを変更する デフォルトではUDPプロト
The USE Method provides a strategy for performing a complete check of system health, identifying common bottlenecks and errors. For each system resource, metrics for utilization, saturation and errors are identified and checked. Any issues discovered are then investigated using further strategies. This is an example USE-based metric list for Linux operating systems (eg, Ubuntu, CentOS, Fedora). Th
Home Subscribe Unixデーモンの仕組み 12 March 2015 おはこんばんちは!! 尾藤 a.k.a. BTO です。 みなさん、Unixデーモンよく使ってますよね。 Webエンジニアなら、Webサーバ、メールサーバ、DBサーバ、cronなどがよく使われるのではないでしょうか。 24時間365日黙々と働き続けるUnixデーモン達。 身近な存在だと思いますが、実はどういう仕組みで動いているのかご存じない方も多いのではないでしょうか。 先日、オトバンクでUnixデーモンの仕組みについて勉強会をやったので、その内容をまとめます。 デーモンとは では、デーモンとはいったい何なのでしょうか。 Unixライクシステムにおいて、バックグランドで動作して様々な処理を実行してくれるプロセスがデーモンです。 デーモンには明確な定義はありませんが、だいたい次のような条件を満たすプロセスが
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く