linux查看进程运行在那个核上

查看进程运行在哪个核上

可以通过下面命令查看linux的进程运行在哪个CPU上以及使用内存的大小

ps -o pid,psr,comm,rss,size -ef

ps auxm

MPI设置的环境变量

MPI进程中相关的环境变量:

  • OMPI_COMM_WORLD_RANK
  • OMPI_COMM_WORLD_SIZE

设置线程的名字

// th_name.c
#include <stdio.h>
#include <pthread.h>

void * f1() {
    printf("f1 : Starting sleep\n");
    sleep(30);
    printf("f1 : Done sleep\n");
}

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;

}
$ gcc th_name.c
$ ./a.out
$ ps -MT -p $(pidof a.out)
LABEL                               PID    SPID TTY          TIME CMD
unconfined                        26124   26124 pts/0    00:00:00 a.out
unconfined                        26124   26125 pts/0    00:00:00 f1_thread
ps -MT -p $(pidof a.out) -o %cpu,pid,tid
%CPU     PID     TID
 0.0   26124       -
 0.0       -   26124
 0.0       -   26125

bash exec命令

./a.out       # a.out 和当前进程的pid[不同]
exec ./a.out  # a.out 和当前进程的pid[相同]
posted @ 2022-12-08 15:38  憶藝  阅读(625)  评论(0)    收藏  举报