Outils pour utilisateurs

Outils du site


tech:notes_processus_multi_thread

Notes processus multi-thread

Source : https://stackoverflow.com/questions/17514771/ps-display-thread-name

th_name.c

#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
 
void *f1(void *arg) {
  (void)arg;
  printf("f1 : Starting sleep\n");
  sleep(30);
  printf("f1 : Done sleep\n");
  return NULL;
}
 
int main() {
  pthread_t f1_thread;
  pthread_create(&f1_thread, NULL, f1, NULL);
  pthread_setname_np(f1_thread, "f1_thread");
 
  printf("Main : Starting sleep\n");
  sleep(40);
  printf("Main : Done sleep\n");
  return 0;
}
$ ps -efLl | egrep "S UID|th_name"
F S UID          PID    PPID     LWP  C NLWP PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
0 S managem+   92168     599   92168  0    2  80   0 -  2741 hrtime 10:34 pts/2    00:00:00 ./th_name
1 S managem+   92168     599   92169  0    2  80   0 -  2741 hrtime 10:34 pts/2    00:00:00 ./th_name
0 S managem+   92176   64256   92176  0    1  80   0 -  1032 anon_p 10:34 pts/18   00:00:00 grep -E --color=auto S UID|th_name

$ ps -efTl | egrep "S UID|th_name"
F S UID          PID    SPID    PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
0 S managem+   92168   92168     599  0  80   0 -  2741 hrtime 10:34 pts/2    00:00:00 ./th_name
1 S managem+   92168   92169     599  0  80   0 -  2741 hrtime 10:34 pts/2    00:00:00 ./th_name
0 S managem+   92187   92187   64256  0  80   0 -  1032 anon_p 10:34 pts/18   00:00:00 grep -E --color=auto S UID|th_name

$ ps -C th_name -L -o nlwp,pid,lwp,comm,command
NLWP     PID     LWP COMMAND         COMMAND
   2   92418   92418 th_name         ./th_name
$ cat /proc/92465/task/92465/comm
th_name

$ cat /proc/92465/task/92466/comm
f1_thread
tech/notes_processus_multi_thread.txt · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki