소프트웨어
[c언어] thread의 상태를 확인해보자
개발자_이훈규
2014. 2. 11. 16:50
1.
thread를 관리하는데 thread의 id인 pid를 통해 관리할 수 있지 않을까라는 발상에서 시작.
2.
googling하니깐 나온다. 'c check pid status'
(https://www.google.com/webhp?hl=en#hl=en&newwindow=1&q=c%20check%20pid%20status&safe=off)
순조로운데?
3.
여기에 다 나와있다. 본인의 pid나 parent의 pid를 확인 할 수 있다.
Kann es auch und macht es nicht
| C++: | ||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/syscall.h> #include <pthread.h> #include <unistd.h> void * thread(void *arg) { sleep(1); printf("T self: %lu\n", pthread_self()); printf("T tid: %lu\n", syscall(SYS_gettid)); printf("T pid: %u\n", getpid()); sleep(60); return 0; } int main() { pthread_t tid; printf("Current proccess: %u\n", getpid()); pthread_create(&tid, NULL, thread, NULL); printf("Started thread: %lu\n", tid); pthread_join(tid, NULL); return 0; } | |
Gab bei mir
| Code: | ||
| Current proccess: 3385 Started thread: 1082132816 T self: 1082132816 T tid: 3387 T pid: 3385 | ||
Und ein pstree dafür ergab:
| Code: | ||
| test_p,3385 `-{test_p},3387 | ||
Wobei in top die 3387 nicht erscheint.