#include #include #include #include #include #include #define THREAD_COUNT 16 pthread_t t_id[THREAD_COUNT]; void * report_pid(void *arg) { int fd = audit_open(); pthread_t id = pthread_self(); pid_t pid = getpid(); char str[16]; for (int i = 0; i < THREAD_COUNT; i++) if (pthread_equal(id, t_id[i])) { printf("Thread %d: PID = %d\n", i, pid); sprintf(str, "thread %d", i); audit_log_user_message(fd, AUDIT_USER, str, NULL, NULL, NULL, 1); } close(fd); return NULL; } int main(int argv, char *argc[]) { printf("Main: PID = %d\n", getpid()); for (int i = 0; i < THREAD_COUNT; i++) { int err = pthread_create(&(t_id[i]), NULL, &report_pid, NULL); if (err != 0) { fprintf(stderr, "Cannot create thread %i: %s\n", i, strerror(err)); exit(EXIT_FAILURE); } } sleep(3); exit(EXIT_SUCCESS); }