Exec関数の0番目のパラメータ

Exec関数の0番目のパラメータ

以下は標準exec*機能です。

int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg,  ..., char * const envp[]);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execvpe(const char *file, char *const argv[], char *const envp[]);

Unix ルールは、実行されるプログラムの名前を引数配列の最初のメンバーに渡すことです。

どんな現実的な文脈で意味のあることをするよりも、慣習から抜け出すのが合理的ですか?パス/ファイルそしてパラメータ/パラメータ v[0]

ベストアンサー1

さまざまな理由から、この違いはプロセスの表示方法を変更するために使用されますps。これらのいくつかは、オペレーティングシステムの変更によって削除されました。

これを念頭に置いて発見されたいくつかの例へのリンクは次のとおりです。

  • execlp()の最初の2つのパラメータに同じ値を渡すのはなぜですか?
    特に、サムミシンボリックリンクを実際のファイルのように「見せる」方法について説明します。
  • hide.c /*---------------------------------------------------------------------------+ | Copyright (c) 1992 Oracle Corporation Belmont, California, USA | | All rights reserved | +---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------+ | FILENAME | | hide.c | | DESCRIPTION | | Hides arguments for programs on UNIX systems. | | Can be used as a program prefix: hide program arguments | | or as a symbolic link. If this program is not invoked as hide, it | | will hide its arguments and invoke the program name.hide | | The best way to use this is to rename your critical programs to | | program.hide, and create a symbolic link program to hide. | | mv sqlplus sqlplus.hide; ln -s hide sqlplus | | Thus when sqlplus is invoked, its arguments will be hidden | | NOTES | | This program works by padding 3000 '/' chars in argv[0]. This fools | | all known ps's. This will reduce the argument capacity of your | | program by 3000 chars. A good enhancement would be to reduce the | | padding if needed so that no arguments are lost - would require a | | method of determining the max argument size on the system. Some | | system's provide the E2BIG error on exec. | | There is some performace penalty for using this program, but it is | | minimal because this program is so small - the biggest cost is the | | extra exec required to get this program started. | | HISTORY | | 09/15/92 R Brodersen Created, based on D Beusee's hideargs() | | 09/17/92 D Beusee Fixed to compile on any system | +---------------------------------------------------------------------------*/

おすすめ記事