スレッド単位とプロセス単位の設定を区別する必要があります。
prctl(PR_SET_NAME、...)はスレッドごとに名前を設定します(例:ps Hcx)。psにその名前を強制的に表示させることができます。一番上のcスイッチでも同じことができるので、htopは同様の機能を持っていると仮定します。
"ps"は通常あなたに表示されます(ps Haxなど)は、あなたがプログラムを起動したコマンドライン名と引数です(実際には/ proc/PID/cmdlineが教えてくれるものです)。 argv [0](元の長さまで)ですが、これはプロセス単位の設定です。つまり、異なるスレッドに異なる名前を与えることはできません。 htop
オプションがある、バージョン0.8.4以来
// procname is the new process name
char *procname = "new process name";
// Then let's directly modify the arguments
// This needs a pointer to the original arvg, as passed to main(),
// and is limited to the length of the original argv[0]
size_t argv0_len = strlen(argv[0]);
size_t procname_len = strlen(procname);
size_t max_procname_len = (argv0_len > procname_len) ? (procname_len) : (argv0_len);
// Copy the maximum
strncpy(argv[0], procname, max_procname_len);
// Clear out the rest (yes, this is needed, or the remaining part of the old
// process name will still show up in ps)
memset(&argv[0][max_procname_len], '\0', argv0_len - max_procname_len);
// Clear the other passed arguments, optional
// Needs to know argv and argc as passed to main()
//for (size_t i = 1; i < argc; i++) {
// memset(argv[i], '\0', strlen(argv[i]));
//}
提出者がいない、スレッドごとの設定を求めていましたか? –
なぜあなたはargv [0]の長さに制限されますか? – user2815333