I'm asking about linux with recent glibc.
Is there a way to detect that process consist of 1 thread or of several threads?
Threads can be created by pthread, or bare clone(), so I need something rather universal.
UPD: I want to detect threads of current process from it itself.
Check if directory /proc/YOUR_PID/task/ contains only one subdirectory. If you have more than one thread in process there will be several subdirs.
The hardlink count can be used to count the subdirectories. This function returns the current number of threads:
#include <sys/stat.h>
int n_threads(void)
{
struct stat task_stat;
if (stat("/proc/self/task", &task_stat))
return -1;
return task_stat.st_nlink - 2;
}