thread-pid course code.
[TD_SE.git] / thread-pid / thread-pid.c
diff --git a/thread-pid/thread-pid.c b/thread-pid/thread-pid.c
new file mode 100644 (file)
index 0000000..a993c77
--- /dev/null
@@ -0,0 +1,18 @@
+#include <unistd.h>     // pour sleep
+#include <pthread.h>    // pthread_create, pthread_join, pthread_exit
+#include <stdio.h>
+
+static void* fonction(void* args) {
+    printf("pid du thread fils = %d\n", getpid());
+    while(1);   // forever
+    return NULL;
+}
+
+int main() {
+    pthread_t thread;
+
+    printf("pid de main = %d\n", getpid());
+    pthread_create(&thread, NULL, &fonction, NULL);
+    while(1);   // forever
+    return 0;
+}