これを入力すると、ps -ef
いくつかの特別なカーネルスレッドプロセスが表示されます。
私はカーネルスレッドには興味がありません。ユーザープロセス/スレッドにのみ興味があります。
カーネルスレッドを隠す方法はありますか?
ベストアンサー1
ps
出力はさまざまな方法でフィルタリングできます。プロセスを表示するには、ユーザー/ UIDでフィルタリングできます。下記の関連マニュアルページ -
U userlist Select by effective user ID (EUID) or name.
This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user
whose file access permissions are used by the process (see geteuid(2)). Identical to -u and --user.
-U userlist Select by real user ID (RUID) or name.
It selects the processes whose real user name or ID is in the userlist list. The real user ID identifies the user
who created the process, see getuid(2).
-u userlist Select by effective user ID (EUID) or name.
This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user
whose file access permissions are used by the process (see geteuid(2)). Identical to U and --user.
カーネルスレッドとユーザースレッドの識別は、カーネルのバージョンによって異なります。私のUbuntuシステム(3.5.0-30-generic)では、kthreadd(pid = 2)の子を除いてカーネルスレッドを除外できます。 kthreaddのpidは2.6カーネルで異なることがあります。ただし、関連するpidを使用できます。たとえば、ppid = 2なしですべてのプロセスのリストを取得するには、次の手順を実行します(-oに指定されているオプションについては、マニュアルページを確認してください)。
ps -o pid,ppid,comm,flags,%cpu,sz,%mem --ppid 2 -N
grepまたはawkを使用してフィルタリングすることもできます。 psを使用せずにカーネルスレッドを識別する別の方法は、/proc//mapsまたは/proc/cmdlineが空であることを確認することです。どちらもカーネルスレッドに対して空です。これを行うにはroot権限が必要です。