Skip to content

Enable setproctitle() on HP-UX#162

Open
michael-o wants to merge 1 commit intodvarrazzo:masterfrom
michael-o:setproctitle-hpux
Open

Enable setproctitle() on HP-UX#162
michael-o wants to merge 1 commit intodvarrazzo:masterfrom
michael-o:setproctitle-hpux

Conversation

@michael-o
Copy link

@michael-o michael-o commented Feb 16, 2026

Works like a charm:

osipovmi@deblndw024v:~
$ uname -a
HP-UX deblndw0 B.11.31 U ia64 HP-UX
osipovmi@deblndw024v:~
$ cat setcmd^C
osipovmi@deblndw024v:~
$ cat test_setproctitle.py
import setproctitle
import time

def main():
#    print("Original title:", setproctitle.getproctitle())

    # Change the process title
    setproctitle.setproctitle("myapp: worker starting up")
#    print("Updated title:", setproctitle.getproctitle())

    # Keep the process alive so you can inspect it with ps/top
    time.sleep(60)

if __name__ == "__main__":
    main()

From ps/top:

osipovmi@deblndw024v:~/py-setproctitle (setproctitle-hpux %=)
$ ps -fu osipovmi
     UID   PID  PPID  C    STIME TTY       TIME COMMAND
osipovmi 17570 17568  0 21:56:09 pts/0     0:00 -sh
osipovmi 20436 17675  1 22:23:11 pts/1     0:00 ps -fu osipovmi
osipovmi 17675 17662  0 21:56:49 pts/1     0:01 bash
osipovmi 17662 17659  0 21:56:47 pts/1     0:00 -sh
osipovmi 17568 17566  0 21:56:09 ?         0:00 sshd: osipovmi@pts/0
osipovmi 20432 17580  0 22:23:04 pts/0     0:00 myapp: worker starting up
osipovmi 17580 17570  0 21:56:13 pts/0     0:00 bash
osipovmi 17659 17647  0 21:56:46 ?         0:00 sshd: osipovmi@pts/1
System: deblndw0                                      Mon Feb 16 22:23:32 2026
Load averages: 0.02, 0.04, 0.03
38 processes: 22 sleeping, 16 running
Cpu states:
CPU   LOAD   USER   NICE    SYS   IDLE  BLOCK  SWAIT   INTR   SSYS
 0    0.02   0.0%   0.0%   0.2%  99.8%   0.0%   0.0%   0.0%   0.0%
 2    0.02   0.0%   0.0%   0.0% 100.0%   0.0%   0.0%   0.0%   0.0%
 4    0.01   0.0%   0.0%   0.0% 100.0%   0.0%   0.0%   0.0%   0.0%
 6    0.02   0.4%   0.0%   0.4%  99.2%   0.0%   0.0%   0.0%   0.0%
---   ----  -----  -----  -----  -----  -----  -----  -----  -----
avg   0.02   0.2%   0.0%   0.2%  99.6%   0.0%   0.0%   0.0%   0.0%

System Page Size: 4Kbytes
Memory: 2125908K (1899044K) real, 4342500K (3833352K) virtual, 20022552K free  Page# 1/1

CPU TTY    PID USERNAME PRI NI   SIZE    RES STATE    TIME %WCPU  %CPU COMMAND
 0 pts/0 20432 osipovmi 168 20 50356K 14744K sleep    0:00  1.79  1.35 myapp:
 4   ?   17047 smartld  152 20   827M   333M run     98:38  0.12  0.12 java

I'll check whether getprocesstitle() can also be made to work.

FTR:

$ file ./build/lib.hp-ux-B.11.31-ia64-cpython-310/setproctitle/_setproctitle.cpython-310.so
./build/lib.hp-ux-B.11.31-ia64-cpython-310/setproctitle/_setproctitle.cpython-310.so:   ELF-32 shared object file - IA64

@michael-o
Copy link
Author

michael-o commented Feb 16, 2026

Setting seems to work:

$ cat get-set-get.c
#include <sys/pstat.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static void get_title(char *buf, size_t buflen) {
    struct pst_status pst;
    union pstun u;

    memset(&pst, 0, sizeof(pst));
    u.pst_status = &pst;

    if (pstat(PSTAT_PROC, u, sizeof(pst), 0, getpid()) == -1) {
        perror("pstat(PSTAT_PROC)");
        exit(1);
    }

    strncpy(buf, pst.pst_cmd, buflen - 1);
    buf[buflen - 1] = '\0';
}

static void set_title(const char *title) {
    union pstun u;
    u.pst_command = (char *)title;

    if (pstat(PSTAT_SETCMD, u, strlen(title), 0, 0) == -1) {
        perror("pstat(PSTAT_SETCMD)");
        exit(1);
    }
}
int main(void) {
    char buf[128];

    /* Show initial title */
    get_title(buf, sizeof(buf));
    printf("Initial title: %s\n", buf);

    /* Change title */
    const char *new_title = "myapp: worker starting up";
    set_title(new_title);

    /* Show updated title */
    get_title(buf, sizeof(buf));
    printf("Updated title: %s\n", buf);

    /* Keep process alive so you can inspect it */
    sleep(60);

    return 0;
}
osipovmi@deblndw024v:~
$ ./get-set-get
Initial title: ./get-set-get
Updated title: myapp: worker starting up
$ ps -fu osipovmi
     UID   PID  PPID  C    STIME TTY       TIME COMMAND
osipovmi 17570 17568  0 21:56:09 pts/0     0:00 -sh
osipovmi 21810 17675  1 22:40:28 pts/1     0:00 ps -fu osipovmi
osipovmi 21809 17580  0 22:40:16 pts/0     0:00 myapp: worker starting up
osipovmi 17675 17662  0 21:56:49 pts/1     0:01 bash
osipovmi 17662 17659  0 21:56:47 pts/1     0:00 -sh
osipovmi 17568 17566  0 21:56:09 ?         0:00 sshd: osipovmi@pts/0
osipovmi 17580 17570  0 21:56:13 pts/0     0:00 bash
osipovmi 17659 17647  0 21:56:46 ?         0:00 sshd: osipovmi@pts/1

Will provide a PR happily after this has been evaluated.

@michael-o
Copy link
Author

After the fix getproctitle() works too since it does use only the cached value...

@dvarrazzo
Copy link
Owner

Hello! Thank you very much, this is super-useful to know.

We should declare that HP-UX is only supported from version 1.3.8 on, which would be our next bugfix, and that the support is on best-effort basis, because we can't run regular regression tests. This should be reflected in the documentation and in the change log.

Are you able to make these changes?

Thank you again!

@michael-o
Copy link
Author

Hello! Thank you very much, this is super-useful to know.

We should declare that HP-UX is only supported from version 1.3.8 on, which would be our next bugfix, and that the support is on best-effort basis, because we can't run regular regression tests. This should be reflected in the documentation and in the change log.

Are you able to make these changes?

Thank you again!

Done, have a look.

@dvarrazzo
Copy link
Owner

If this works for you we can commit it and I will make a new release. Thank you very much!

@michael-o
Copy link
Author

If this works for you we can commit it and I will make a new release. Thank you very much!

Yes, absolutely. Looking forward to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants