- 論壇徽章:
- 0
|
我通過pthread_create創(chuàng)建了一個(gè)線程,然后想讓這個(gè)線程停住。
由于使用的是NPTL庫,所以想到了tkill系統(tǒng)調(diào)用。但是現(xiàn)在通過tkill發(fā)送一個(gè)SIGSTOP信號(hào)給線程之后,整個(gè)線程組中的所有線程都停下來了。
請(qǐng)問一下怎樣才可以使進(jìn)程中的某一個(gè)線程停住?(聽別人說tkill系統(tǒng)調(diào)用可以,可我怎么試都不行呢?)
謝謝先。
附我的測(cè)試代碼:
A:多線程程序:
- static void test_task_print()
- {
- while(1) {
- printf("Task is executingn" );
- sleep(5);
- }
- }
- int main(int argc, char *argv[])
- {
- int tid;
- pthread_t t;
- pthread_create(&t, NULL, test_task_print, NULL);
- while(1) {
- sleep(250);
- }
- return 0;
- }
復(fù)制代碼
B:信號(hào)發(fā)送程序
- int main(int argc, char *argv[])
- {
- int tid;
- if (argc != 2) {
- printf("usage: ./kill_send sig\n");
- return -1;
- }
- tid = atoi(argv[1]);
- syscall(__NR_tkill, tid, SIGSTOP);
- printf("send signal to thread %d\n", tid);
- return 0;
- }
復(fù)制代碼 |
|