Нужен гид по созданию процессов - C (СИ)
Формулировка задачи:
Здравствуйте. В интернете почти не ничего не нашел по этой теме.
Интересуем мануал по созданию и управлению процессами в С.
Спасибо.
Решение задачи: «Нужен гид по созданию процессов»
textual
Листинг программы
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
void * thread_func(void * threadName) {
int i;
for ( i = 5; i > 0; --i ) {
printf("%s: %d\n", (char*)threadName, i);
usleep(rand() % 100 * 10000);
}
return (NULL);
}
int main(void) {
pthread_t t1, t2;
srand(time(NULL));
assert ( pthread_create(&t1, NULL, thread_func, "Thread #1") == 0 );
assert ( pthread_create(&t2, NULL, thread_func, "Thread #2") == 0 );
assert ( pthread_join(t1, NULL) == 0 );
assert ( pthread_join(t2, NULL) == 0 );
exit(0);
}