精华内容
下载资源
问答
  • setproctitle
    2021-11-11 22:15:33

    自定设置进程名python模块:setproctitle

    git clone https://github.com/dvarrazzo/py-setproctitle.git
    cd py-setproctitle
    python setup.py build
    python setup.py install
    pip install setproctitle
    
    
    
    
    
    import setproctitle
    setproctitle.setproctitle("进程别名")
    
    
    
    更多相关内容
  • setproctitle-1.2.2-pp37-pypy37_pp73-win_amd64
  • setproctitle-1.1.10-cp27-cp27m-win32
  • setproctitle-1.1.10-cp35-cp35m-win_amd64
  • setproctitle-1.1.10-cp34-cp34m-win32
  • setproctitle-1.2.2-cp38-cp38-win_amd64
  • 官方离线安装包,亲测可用
  • 官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
  • python离线安装包,亲测可用
  • setproctitle-1.1.10-cp34-cp34m-win_amd64
  • setproctitle-1.2.2-cp37-cp37m-win_amd64
  • 设置程序标题用于设置进程标题的实用程序,如 htop/ps 等所示...需要 Linux >=3.5 有关使用说明,请参阅随附的手册页或使用 -h 运行。安装: aclocal && autoconf && autoheader && automake --add-missing ./...
  • 用于自定义流程标题的Python模块 作者: 丹妮尔·瓦拉佐(Daniele Varrazzo) setproctitle模块允许进程更改其标题(如ps和top类的系统工具所显示)。 更改标题在多进程系统中最有用,例如,在主流程被分叉时:更改...
  • setproctitle

    2021-04-23 20:48:17
    See https://wiki.php.net/rfc/cli_process_title, which says: "...but it is incomplete and might lead to memory corruption on Linux (or any OS which does not support setproctitle....

    [#2]

    zodbd421 at gmail dot com [2013-04-21 05:16:02]

    Note that this extension is considered buggy.  See https://wiki.php.net/rfc/cli_process_title, which says:

    "...but it is incomplete and might lead to memory corruption on Linux (or any OS which does not support setproctitle.

    The reason is the extension only has access to original argv[0] (that comes from main()). argv and environ(7) are in contiguous memory space on Linux. The extension presumes that argv[0] can accomodate 128 characters, but usually that is not possible because argv[0] is ??php??. When this happens, the extension will scribble on argv[1], argv[2], etc., and maybe even environ and this can have destructive side effects on the running program."

    展开全文
  • setproctitle.c

    2021-04-23 20:48:22
    /* ==========================================================================* setproctitle.c - Linux/Darwin setproctitle.* --------------------------------------------------------------------------* ...

    /* ==========================================================================

    * setproctitle.c - Linux/Darwin setproctitle.

    * --------------------------------------------------------------------------

    * Copyright (C) 2010 William Ahern

    * Copyright (C) 2013 Salvatore Sanfilippo

    * Copyright (C) 2013 Stam He

    *

    * Permission is hereby granted, free of charge, to any person obtaining a

    * copy of this software and associated documentation files (the

    * "Software"), to deal in the Software without restriction, including

    * without limitation the rights to use, copy, modify, merge, publish,

    * distribute, sublicense, and/or sell copies of the Software, and to permit

    * persons to whom the Software is furnished to do so, subject to the

    * following conditions:

    *

    * The above copyright notice and this permission notice shall be included

    * in all copies or substantial portions of the Software.

    *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS

    * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

    * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN

    * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,

    * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

    * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE

    * USE OR OTHER DEALINGS IN THE SOFTWARE.

    * ==========================================================================

    */

    #ifndef _GNU_SOURCE

    #define _GNU_SOURCE

    #endif

    #include /* NULL size_t */

    #include /* va_list va_start va_end */

    #include /* malloc(3) setenv(3) clearenv(3) setproctitle(3) getprogname(3) */

    #include /* vsnprintf(3) snprintf(3) */

    #include /* strlen(3) strchr(3) strdup(3) memset(3) memcpy(3) */

    #include /* errno program_invocation_name program_invocation_short_name */

    #if !defined(HAVE_SETPROCTITLE)

    #if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)

    #define HAVE_SETPROCTITLE 1

    #else

    #define HAVE_SETPROCTITLE 0

    #endif

    #endif

    #if !HAVE_SETPROCTITLE

    #if (defined __linux || defined __APPLE__)

    extern char **environ;

    static struct {

    /* original value */

    const char *arg0;

    /* title space available */

    char *base, *end;

    /* pointer to original nul character within base */

    char *nul;

    _Bool reset;

    int error;

    } SPT;

    #ifndef SPT_MIN

    #define SPT_MIN(a, b) (((a) < (b))? (a) : (b))

    #endif

    static inline size_t spt_min(size_t a, size_t b) {

    return SPT_MIN(a, b);

    } /* spt_min() */

    /*

    * For discussion on the portability of the various methods, see

    * http://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html

    */

    static int spt_clearenv(void) {

    #if __GLIBC__

    clearenv();

    return 0;

    #else

    extern char **environ;

    static char **tmp;

    if (!(tmp = malloc(sizeof *tmp)))

    return errno;

    tmp[0] = NULL;

    environ = tmp;

    return 0;

    #endif

    } /* spt_clearenv() */

    static int spt_copyenv(char *oldenv[]) {

    extern char **environ;

    char *eq;

    int i, error;

    if (environ != oldenv)

    return 0;

    if ((error = spt_clearenv()))

    goto error;

    for (i = 0; oldenv[i]; i++) {

    if (!(eq = strchr(oldenv[i], '=')))

    continue;

    *eq = '\0';

    error = (0 != setenv(oldenv[i], eq + 1, 1))? errno : 0;

    *eq = '=';

    if (error)

    goto error;

    }

    return 0;

    error:

    environ = oldenv;

    return error;

    } /* spt_copyenv() */

    static int spt_copyargs(int argc, char *argv[]) {

    char *tmp;

    int i;

    for (i = 1; i < argc || (i >= argc && argv[i]); i++) {

    if (!argv[i])

    continue;

    if (!(tmp = strdup(argv[i])))

    return errno;

    argv[i] = tmp;

    }

    return 0;

    } /* spt_copyargs() */

    void spt_init(int argc, char *argv[]) {

    char **envp = environ;

    char *base, *end, *nul, *tmp;

    int i, error;

    if (!(base = argv[0]))

    return;

    nul = &base[strlen(base)];

    end = nul + 1;

    for (i = 0; i < argc || (i >= argc && argv[i]); i++) {

    if (!argv[i] || argv[i] < end)

    continue;

    end = argv[i] + strlen(argv[i]) + 1;

    }

    for (i = 0; envp[i]; i++) {

    if (envp[i] < end)

    continue;

    end = envp[i] + strlen(envp[i]) + 1;

    }

    if (!(SPT.arg0 = strdup(argv[0])))

    goto syerr;

    #if __GLIBC__

    if (!(tmp = strdup(program_invocation_name)))

    goto syerr;

    program_invocation_name = tmp;

    if (!(tmp = strdup(program_invocation_short_name)))

    goto syerr;

    program_invocation_short_name = tmp;

    #elif __APPLE__

    if (!(tmp = strdup(getprogname())))

    goto syerr;

    setprogname(tmp);

    #endif

    if ((error = spt_copyenv(envp)))

    goto error;

    if ((error = spt_copyargs(argc, argv)))

    goto error;

    SPT.nul = nul;

    SPT.base = base;

    SPT.end = end;

    return;

    syerr:

    error = errno;

    error:

    SPT.error = error;

    } /* spt_init() */

    #ifndef SPT_MAXTITLE

    #define SPT_MAXTITLE 255

    #endif

    void setproctitle(const char *fmt, ...) {

    char buf[SPT_MAXTITLE + 1]; /* use buffer in case argv[0] is passed */

    va_list ap;

    char *nul;

    int len, error;

    if (!SPT.base)

    return;

    if (fmt) {

    va_start(ap, fmt);

    len = vsnprintf(buf, sizeof buf, fmt, ap);

    va_end(ap);

    } else {

    len = snprintf(buf, sizeof buf, "%s", SPT.arg0);

    }

    if (len <= 0)

    { error = errno; goto error; }

    if (!SPT.reset) {

    memset(SPT.base, 0, SPT.end - SPT.base);

    SPT.reset = 1;

    } else {

    memset(SPT.base, 0, spt_min(sizeof buf, SPT.end - SPT.base));

    }

    len = spt_min(len, spt_min(sizeof buf, SPT.end - SPT.base) - 1);

    memcpy(SPT.base, buf, len);

    nul = &SPT.base[len];

    if (nul < SPT.nul) {

    *SPT.nul = '.';

    } else if (nul == SPT.nul && &nul[1] < SPT.end) {

    *SPT.nul = ' ';

    *++nul = '\0';

    }

    return;

    error:

    SPT.error = error;

    } /* setproctitle() */

    #endif /* __linux || __APPLE__ */

    #endif /* !HAVE_SETPROCTITLE */

    一键复制

    编辑

    Web IDE

    原始数据

    按行查看

    历史

    展开全文
  • 原理:进程名被保存在 argv[0] 中,所有要改动进程名,只需要改动 argv[0],但是 argv[] 后续会跟 environ 环境变量内容,如果要 利用到传入的参数,以及环境变量,则需要先申请新的空间...void init_setproctitle(...

    原理:进程名被保存在 argv[0] 中,所有要改动进程名,只需要改动 argv[0],但是 argv[] 后续会跟 environ 环境变量内容,如果要 利用到传入的参数,以及环境变量,则需要先申请新的空间,将这些信息保存下来。[以下代码没有保存 environ]

    #include

    char** os_argv;

    char* os_argv_last;

    void init_setproctitle()

    {

    char * p;

    size_t size;

    int i;

    size = 0;

    os_argv_last = os_argv[0];

    for (i = 0; os_argv[i]; ++i)

    {

    if (os_argv_last == os_argv[i])

    {

    size += strlen(os_argv[i]) + 1;

    printf("i:%d size:%d\n", i, size);

    os_argv_last = os_argv[i] + strlen(os_argv[i]) + 1;

    }

    }

    printf("len:%d os_argv_last:%s\n", os_argv_last - os_argv[0], os_argv_last);

    // 移动到了环境变量的最后

    os_argv_last += strlen(os_argv_last);

    }

    void save_argv(int argc, const char** argv)

    {

    os_argv = (char **) argv;

    }

    void setproctitle(char *title)

    {

    char *p;

    os_argv[1] = NULL;

    p = strncpy((char *) os_argv[0], (char *) title,

    strlen(title));

    p += strlen(title);

    if (os_argv_last - (char *) p > 0) {

    printf("后面部分清零\n");

    memset(p, 0, os_argv_last - (char *) p);

    }

    }

    int main(int argc, char** argv)

    {

    save_argv(argc, argv);

    init_setproctitle();

    setproctitle("titlename");

    printf("%s\n", argv[0]);

    while (1) ;

    return 0;

    }

    展开全文
  • setproctitle:设置Python进程名称2019-12-17T02:07:1289300#### 在Linux等系统中,我们经常希望根据进程名称查询进程信息,那么对于一个Python程序,怎么才能自定义设置一个镜像名称呢?#### 本文将会主要讲解...
  • 正常报这种错误是因为模块缺失,我们正常安装即可: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple setproctitle ... PS:当然如果不放心该包有没有用,安装setproctitle完毕后可以再将enum34装回来 <_<
  • 一、原因 选择的编译解释器中,没安装这个库 二、解决方法 1、未装Anaconda环境下 ...输入:pip install setproctitle 2、装Anaconda环境下 打开Anaconda Prompt 输入:conda install setproctitle ...
  • 不用这个语句,进程显示是python。用这个进程显示‘进程别名’。
  • setproctitle-1.2.2-cp39-cp39-win32
  • setproctitle-1.2.2-cp38-cp38-win32
  • setproctitle-1.2.2-cp310-cp310-win32
  • setproctitle-1.2.2-cp37-cp37m-win32
  • setproctitle-1.2.1-cp36-cp36m-win32
  • setproctitle-1.1.10-cp35-cp35m-win32
  • setproctitle-1.2.2-cp39-cp39-win_amd64
  • setproctitle-1.2.2-cp310-cp310-win_amd64
  • setproctitle-1.2.1-cp36-cp36m-win_amd64
  • setproctitle-1.1.10-cp27-cp27m-win_amd64

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,055
精华内容 1,222
关键字:

setproctitle