-
-
Save shkhln/af421368a36727926ad9103e8f59b455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% /compat/linux/bin/gcc multiple_threads.c -pthread -o test | |
% ./test | |
thread_start: 3 | |
[[0x7ffffff995b0]] | |
thread_start: 2 | |
[[0x821182e30]] | |
thread_start: 1 | |
[[0x84119ce30]] | |
thread_start: 0 | |
[[0x867f9be30]] | |
00000008211d0000-00000008411d0000 rw-p 00000000 00:00 0 | |
0000000844000000-0000000844021000 rw-p 00000000 00:00 0 | |
0000000844021000-0000000848001000 ---p 00000000 00:00 0 | |
0000000848001000-0000000868001000 rw-p 00000000 00:00 0 | |
000000086c000000-000000086c021000 rw-p 00000000 00:00 0 | |
000000086c021000-0000000870000000 ---p 6ae58000 00:00 0 | |
00007fffdffff000-00007ffffff7f000 ---p 00000000 00:00 0 | |
00007ffffff7f000-00007ffffffdf000 rw-p 00000000 00:00 0 | |
00007ffffffdf000-00007ffffffff000 rw-p 00000000 00:00 0 [stack] | |
00007ffffffff000-0000800000000000 r-xs 00000000 00:00 0 [vdso] | |
PID START END PRT RES PRES REF SHD FLAG TP PATH | |
2303 0x400000 0x401000 r-x 1 2 2 1 CN--- vn /<...>/test | |
2303 0x600000 0x601000 r-- 1 0 1 0 CN--- vn /<...>/test | |
2303 0x601000 0x623000 rw- 2 2 1 0 CN--- df | |
2303 0x800600000 0x800622000 r-x 33 34 6 3 CN--- vn /compat/linux/usr/lib64/ld-2.17.so | |
2303 0x800622000 0x800623000 rw- 1 1 1 0 CN--- df | |
2303 0x800630000 0x800633000 rw- 2 2 1 0 CN--- df | |
2303 0x800821000 0x800822000 r-- 1 0 1 0 CN--- vn /compat/linux/usr/lib64/ld-2.17.so | |
2303 0x800822000 0x800824000 rw- 2 2 1 0 CN--- df | |
2303 0x800a00000 0x800a17000 r-x 23 24 4 2 CN--- vn /compat/linux/usr/lib64/libpthread-2.17.so | |
2303 0x800a17000 0x800c16000 --- 1 24 4 2 CN--- vn /compat/linux/usr/lib64/libpthread-2.17.so | |
2303 0x800c16000 0x800c17000 r-- 1 0 1 0 CN--- vn /compat/linux/usr/lib64/libpthread-2.17.so | |
2303 0x800c17000 0x800c18000 rw- 1 0 1 0 CN--- vn /compat/linux/usr/lib64/libpthread-2.17.so | |
2303 0x800c18000 0x800c1c000 rw- 1 1 1 0 CN--- df | |
2303 0x800e00000 0x800fc3000 r-x 363 369 11 5 CN--- vn /compat/linux/usr/lib64/libc-2.17.so | |
2303 0x800fc3000 0x8011c3000 --- 6 369 11 5 CN--- vn /compat/linux/usr/lib64/libc-2.17.so | |
2303 0x8011c3000 0x8011c7000 r-- 4 0 1 0 CN--- vn /compat/linux/usr/lib64/libc-2.17.so | |
2303 0x8011c7000 0x8011c9000 rw- 2 0 1 0 CN--- vn /compat/linux/usr/lib64/libc-2.17.so | |
2303 0x8011c9000 0x8011ce000 rw- 3 3 1 0 CN--- df | |
2303 0x8011ce000 0x8011cf000 --- 0 0 1 0 CN--- df | |
2303 0x8011cf000 0x8211cf000 rw- 80 80 1 0 CN--- df | |
2303 0x8211cf000 0x8211d0000 --- 0 0 1 0 CN--- df | |
2303 0x8211d0000 0x8411d0000 rw- 55 55 1 0 CN--- df | |
2303 0x844000000 0x844021000 rw- 1 1 1 0 CN--- df | |
2303 0x844021000 0x848001000 --- 0 0 1 0 CN--- df | |
2303 0x848001000 0x868001000 rw- 105 105 1 0 C---- df | |
2303 0x86c000000 0x86c021000 rw- 1 1 1 0 CN--- df | |
2303 0x86c021000 0x870000000 --- 0 0 1 0 CN--- df | |
2303 0x7fffdffff000 0x7ffffff7f000 --- 0 0 0 0 ----- -- | |
2303 0x7ffffff7f000 0x7ffffffdf000 rw- 73 73 1 0 CN-D- df | |
2303 0x7ffffffdf000 0x7ffffffff000 rw- 32 32 1 0 CN-D- df | |
2303 0x7ffffffff000 0x800000000000 r-x 1 1 4 0 ----- ph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xubuntu@xubuntu:~$ cc multiple_threads.c -pthread -o test | |
xubuntu@xubuntu:~$ ./test | |
thread_start: 3 | |
[[0x7ffc27e05060]] | |
thread_start: 2 | |
[[0x7fb6a36e2e10]] | |
thread_start: 1 | |
[[0x7fb6a311ee10]] | |
thread_start: 0 | |
[[0x7fb6a2b0fe10]] | |
7fb6a395d000-7fb6a395e000 r--p 00000000 00:19 4481 /usr/lib/x86_64-linux-gnu/ld-2.31.so | |
7fb6a395e000-7fb6a3981000 r-xp 00001000 00:19 4481 /usr/lib/x86_64-linux-gnu/ld-2.31.so | |
7fb6a3981000-7fb6a3989000 r--p 00024000 00:19 4481 /usr/lib/x86_64-linux-gnu/ld-2.31.so | |
7fb6a398a000-7fb6a398b000 r--p 0002c000 00:19 4481 /usr/lib/x86_64-linux-gnu/ld-2.31.so | |
7fb6a398b000-7fb6a398c000 rw-p 0002d000 00:19 4481 /usr/lib/x86_64-linux-gnu/ld-2.31.so | |
7fb6a398c000-7fb6a398d000 rw-p 00000000 00:00 0 | |
7ffc27e02000-7ffc27e6c000 rw-p 00000000 00:00 0 [stack] | |
7ffc27f45000-7ffc27f48000 r--p 00000000 00:00 0 [vvar] | |
7ffc27f48000-7ffc27f49000 r-xp 00000000 00:00 0 [vdso] | |
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] | |
sh: 1: procstat: not found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
void* thread_start(void* arg) { | |
long i = (long)arg; | |
fprintf(stderr, "%s: %ld\n", __func__, i); | |
// allocate something on stack | |
int n = (1 + rand() % 4) * 100 * 1024; | |
char a[n]; | |
memset(a, 0, n); | |
fprintf(stderr, "[[%p]]\n", a); | |
if (i == 0) { | |
{ | |
char cmd[100]; | |
#ifdef __FreeBSD__ | |
snprintf(cmd, sizeof(cmd), "cat /compat/linux/proc/%d/maps | tail -n 10", getpid()); | |
#else | |
snprintf(cmd, sizeof(cmd), "cat /proc/%d/maps | tail -n 10", getpid()); | |
#endif | |
system(cmd); | |
} | |
{ | |
char cmd[100]; | |
snprintf(cmd, sizeof(cmd), "procstat -v %d | tail -n 40", getpid()); | |
system(cmd); | |
} | |
} else { | |
pthread_t t; | |
int err = pthread_create(&t, NULL, &thread_start, (void*)(i - 1)); | |
if (err != 0) { | |
fprintf(stderr, "pthread_create: %s\n", strerror(err)); | |
} | |
sleep(1); | |
} | |
return 0; | |
} | |
int main() { | |
thread_start((void*)3); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment