Как я могу просмотреть потоки для запущенного процесса, создающего потоки?

Заключите свой сценарий примерно так:

while true
do
  ... your script here
done

У вас уже есть условие выхода, так что это должно сработать. Если это не так, укажите причину сбоя

0
05.04.2019, 00:27
1 ответ

Два дополнительных потока записывают свое сообщение и завершаются, поэтому у вас нет времени, чтобы увидеть их с помощью ps.

изman pthread_create:

The new thread terminates in one of the following ways:

* It calls pthread_exit(3), specifying an exit status value that is available to another thread in the same process that calls pthread_join(3).

* It returns from start_routine(). This is equivalent to calling pthread_exit(3) with the value supplied in the return statement.

[...]

Вы можете следить за тем, что происходит, например, с помощьюstrace:

$ strace -f -e trace=clone,exit./a.out 
clone(strace: Process 409 attached
child_stack=0x7f7126930ff0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f71269319d0, tls=0x7f7126931700, child_tidptr=0x7f71269319d0) = 409
[pid   408] clone(strace: Process 410 attached
child_stack=0x7f712612fff0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f71261309d0, tls=0x7f7126130700, child_tidptr=0x7f71261309d0) = 410
Am a new thread!
Am a new thread!
647173888
638781184
[pid   409] exit(0 <unfinished...>
[pid   410] exit(0 <unfinished...>
[pid   409] <... exit resumed>)         = ?
[pid   410] <... exit resumed>)         = ?
[pid   410] +++ exited with 0 +++
[pid   409] +++ exited with 0 +++
0
28.01.2020, 03:51

Теги

Похожие вопросы