LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2006, 12:28 PM   #1
mannahazarika
Member
 
Registered: Dec 2005
Posts: 41

Rep: Reputation: Disabled
POSIX Threads


I have two questions/doubts:-

1) Are there any system calls that will give the thread id of the currently running thread?

2) How to make a thread respond to a signal?

I had tried making a simple program where the main program first makes a thread which will print the character‘t’ in the standard output in an infinite loop, and the main program will print the character ‘m’ in the standard output. A signal handler for the signal SIGINT was installed in the main program which will print “You pressed ctrl+c” and will exit. Now, while executing the program, when the main program was executing (printing ‘m’ in the terminal), pressing ctrl+c was caught by the signal handler and printed the desired output. “You pressed ctrl+c” and exited.
But when the thread was executing (printing‘t’ in the terminal), pressing ctrl+c had no effect at all. I tried installing a separate signal handler in the thread by including the ‘signal()’ system call in the function which the thread was executing. Still there was no effect.

So how to make the thread handle signals?
 
Old 07-15-2006, 03:01 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Threads don't respond to signals - *processes* respond to signals. Threads execute within a process.
 
Old 07-15-2006, 10:49 PM   #3
mannahazarika
Member
 
Registered: Dec 2005
Posts: 41

Original Poster
Rep: Reputation: Disabled
So how can I make the process respond to signals while a particular thread is executings?
 
Old 07-15-2006, 11:43 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You'd better tell what O/S, kernel and thread implementation you are using.

For example, LinuxThreads is far from being compliant to the POSIX model, you may want to look at the BUGS section of pthread_kill manual page on your system.
 
Old 07-16-2006, 11:00 PM   #5
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
pthread_self

hi,
You can use pthread_self to get the current thread id, but its not a system call.

Regards,
Rajesh.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
POSIX threads policy and priority arunj Programming 1 06-13-2006 06:05 PM
POSIX threads - pthread_cond_timedwait iklinux Programming 5 09-26-2005 10:33 AM
About POSIX threads Ephracis Programming 1 12-03-2004 06:33 AM
enable pthreads? (posix threads) cpluspaul Slackware 5 06-29-2004 05:56 AM
I have a problem with POSIX Threads. AndreasA Programming 2 08-11-2003 02:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration