ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This will set the current mask to maskall, and store the old masks in maskold so they can be restored later.
Have you tried reading the man pages? You might want to try 'apt-get install manpages manpages-dev' on Debian/Ubuntu, not sure about other distros but then there will be something similar. Then 'man sigprocmask' should give you all the info you need on that particular function (and the others in your example.
I have another doubt though , if sigsuspend restores the mask, why is this required ?
sigprocmask(SIG_SETMASK, &maskold, NULL);
First of all, the signal mask holds al those signals which should be blocked by the application. Though, by using maskmost, you would block all signals except SIGUSR1. For more details, please check the man pages as suggested by John or the POSIX rationale/spec which contains very useful information about how signals are handled, when signals are blocked, when they are just suspended, etc.
Regarding your second question, why this second sigprocmask(2) is required: please verify your code that maskmost != maskall != maskold. Though the last statement just restores the maskold state while sigsuspend restores from maskmost to maskall.
Thanks forza , i think i got what is happening now... Early on all signals are blocked , then all signals except sigusr1 is blocked, on receipt the state is restored to the last configuration.
This is a way to prevent a signal being missed from the looks of it.
I am now going to hijack this in a new direction -> Sockets!
When speaking of file descriptors, as i understand it is nothing more than an integer. This is an excerpt from Beej's guide to n/w programming. Stripped for clarity.
Code:
select(maxfd+1, &readfd,NULL,NULL,NULL)
for(int i =0;;i<maxfd ; i++)
if(FD_ISSET(i,&readfd))
first up , there is no ordering between the fd's returned by the OS if i understand correctly. So read fd could have fd's like 10,24,28,32. Does this make sense to iterate all they way from 0 to maxfd??
PS: My unix box is dead atm , hence i am asking some silly stuff which would be clearer to program .
Cheers!
Last edited by Khaj.pandey; 06-18-2010 at 01:19 PM.
You didn't really ask any explicit question, though I'm just commenting some of your statements :-)
Quote:
Originally Posted by Khaj.pandey
When speaking of file descriptors, as i understand it is nothing more than an integer. This is an excerpt from Beej's guide to n/w programming. Stripped for clarity.
Yes, file descriptors are integer values
Quote:
Originally Posted by Khaj.pandey
first up , there is no ordering between the fd's returned by the OS if i understand correctly. So read fd could have fd's like 10,24,28,32. Does this make sense to iterate all they way from 0 to maxfd??
Well, it depends on what you understand by ordering. The file/socket descriptors returned by the OS are in a specific order. The OS returns the lowest available socket descriptor, starting at 3 (due to stdin, stdout, stderr) for a newly created program. For example, if you would close stdin before creating a new socket, you'll get a socket id of 0.
As i understand, the complete data might not be sent in one go by the send command... i.e. which pretty much means, the complete data is not recovered at the other end.... Any mechanisms to handle this ? i.e. if one was to write a structure and send it (only half is sent), and only half is received then how is the same handled?
From the top of my head , i would say , allocating memory using malloc , copying as much as you can in it.... doing a memcpy of the address returned via malloc + data read and the new offset. Obviously all this with another send by te sender.
I theory this sounds nice, not sure if it actually works.
Last edited by Khaj.pandey; 06-19-2010 at 07:56 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.