so true

          心懷未來,開創未來!
          隨筆 - 160, 文章 - 0, 評論 - 40, 引用 - 0
          數據加載中……

          如何修改進程的命令行

          下面這段代碼摘自php/sapi/fpm/fpm/fpm_env.c
          /*
          * This piece of code has been inspirated from nginx and pureftpd code, whic
          * are under BSD licence.
          *
          * To change the process title in Linux we have to set argv[1] to NULL
          * and to copy the title to the same place where the argv[0] points to.
          * However, argv[0] may be too small to hold a new title.  Fortunately, Linux
          * store argv[] and environ[] one after another.  So we should ensure that is
          * the continuous memory and then we allocate the new memory for environ[]
          * and copy it.  After this we could use the memory starting from argv[0] for
          * our process title.
          */
          for (i = 0; i < fpm_globals.argc; i++) {
          if (first == NULL) {
          first = fpm_globals.argv[i];
          }
          if (last == NULL || fpm_globals.argv[i] == last + 1) {
          last = fpm_globals.argv[i] + strlen(fpm_globals.argv[i]);
          }
          }
          if (environ) {
          for (i = 0; environ[i]; i++) {
          if (first == NULL) {
          first = environ[i];
          }
          if (last == NULL || environ[i] == last + 1) {
          last = environ[i] + strlen(environ[i]);
          }
          }
          }
          if (first == NULL || last == NULL) {
          return 0;
          }
          fpm_env_argv_len = last - first;
          fpm_env_argv = fpm_globals.argv;
          if (environ != NULL) {
          char **new_environ;
          unsigned int env_nb = 0U;
          while (environ[env_nb]) {
          env_nb++;
          }
          if ((new_environ = malloc((1U + env_nb) * sizeof (char *))) == NULL) {
          return -1;
          }
          new_environ[env_nb] = NULL;
          while (env_nb > 0U) {
          env_nb--;
          new_environ[env_nb] = strdup(environ[env_nb]);
          }
          environ = new_environ;
          }
          #endif
          #endif
          spprintf(&title, 0, "master process (%s)", fpm_globals.config);
          fpm_env_setproctitle(title); 
          efree(title);

          posted on 2012-12-21 15:18 so true 閱讀(411) 評論(0)  編輯  收藏 所屬分類: C&C++Linux

          主站蜘蛛池模板: 康乐县| 宜昌市| 天柱县| 太谷县| 普定县| 丰台区| 招远市| 罗甸县| 那曲县| 临高县| 岑巩县| 临武县| 永福县| 灵山县| 濮阳市| 罗田县| 新安县| 海淀区| 谷城县| 通辽市| 兴仁县| 巴彦淖尔市| 内丘县| 新干县| 绿春县| 海伦市| 得荣县| 广河县| 鸡东县| 邵阳市| 凤冈县| 湟源县| 区。| 丹寨县| 西青区| 舒兰市| 崇明县| 临邑县| 讷河市| 客服| 石屏县|