Am coming across a flag SA_RESTART in signal sigact structure. What does
this flag actually representing. I could not get the full meaning of
this flag from the man page. Can anybody explain me better, the
consequence of with and without this flag in sigact structure. What will
happen if this flag presents or if not present. kindly explain me.
TIA,
Nix
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
> Hi,
>
> Am coming across a flag SA_RESTART in signal sigact structure. What does
> this flag actually representing. I could not get the full meaning of
> this flag from the man page. Can anybody explain me better, the
> consequence of with and without this flag in sigact structure. What will
> happen if this flag presents or if not present. kindly explain me.
>
When a signal is deliverd while the program is in a system call, this call
can get aborted and returns with an error (and ususally errno==EINTR). With
SA_RESTART, the system call is restarted when the signal handler returns.
Tobias.
--
unix http://www.faqs.org/faqs/by-newsgroup/comp/comp.unix.programmer.html
clc http://www.eskimo.com/~scs/C-faq/top.html
fclc (french): http://www.isty-info.uvsq.fr/~rumeau/fclc/
> Dexter Nixon wrote:
>
> > Hi,
> >
> > Am coming across a flag SA_RESTART in signal sigact structure. What does
> > this flag actually representing. I could not get the full meaning of
> > this flag from the man page. Can anybody explain me better, the
> > consequence of with and without this flag in sigact structure. What will
> > happen if this flag presents or if not present. kindly explain me.
> >
>
> When a signal is deliverd while the program is in a system call, this call
> can get aborted and returns with an error (and ususally errno==EINTR). With
> SA_RESTART, the system call is restarted when the signal handler returns.
> Tobias.
---------------------------------------------------------------------------
Thanks for the response. I found simillar kind of explanation in the man
page too. But still i am not clear with one thing. When the system call
is executed means, the process is runnign the call in kernel mode. If a
signal received and for which a handler is already registered with this
SA_RESTART flags set means, it will restart the system call or what.
Suppose, if the process is executing a write syscall and in the half way
of writing, if a signal is received means, it will restart the system
call again, writing from the start again or what. also on what context
the signal handler will get executed. If it in the same task context
means why does this behaviour of restarting, simply a stack push and pop
will do right. Why do we restart the syscall. Is that a meaningful
question. kindly explain me.
Thanks,
If a system call returns failure with EINTR, it means that
the system call was aborted before it could be completed.
If SA_RESTART is not set in your signal handler installation,
then you would have to retry your system call. SA_RESTART
indicates that you wish for the system to transparently
do the retry without throwing the EINTR failure.
--
Fletcher Glenn
email f-g-l...@quest.com (remove the dashes)
> "Tobias Oed" <tob...@physics.odu.edu> wrote in message
> news:a82c97$olobv$1...@ID-97389.news.dfncis.de...
>
>> Dexter Nixon wrote:
>>
>> > Hi,
>> >
>> > Am coming across a flag SA_RESTART in signal sigact structure. What
>> > does this flag actually representing. I could not get the full meaning
>> > of this flag from the man page. Can anybody explain me better, the
>> > consequence of with and without this flag in sigact structure. What
>> > will happen if this flag presents or if not present. kindly explain me.
>> >
>>
>> When a signal is deliverd while the program is in a system call, this
>> call can get aborted and returns with an error (and ususally
>> errno==EINTR). With SA_RESTART, the system call is restarted when the
>> signal handler returns. Tobias.
>
>
>
---------------------------------------------------------------------------
>
> Thanks for the response. I found simillar kind of explanation in the man
> page too. But still i am not clear with one thing. When the system call
> is executed means, the process is runnign the call in kernel mode. If a
> signal received and for which a handler is already registered with this
> SA_RESTART flags set means, it will restart the system call or what.
Yes, the system call will be restarted. (Note that this whole discussion
only applies to slow system calls: read/writes to files that can block (not
disk) open of files that can block (like terminals), and some ioctl calls.)
This is to avoid having to write code like this all over the place:
again:
if (( n=read(...) )<0){
if(errno==EINTR)
goto again;
> Suppose, if the process is executing a write syscall and in the half way
> of writing, if a signal is received means, it will restart the system
> call again, writing from the start again or what. also on what context
A signal will interupte/restart a write only if no data has been written.
> also on what context the signal handler will get executed.
user
> If it in the same task context
> means why does this behaviour of restarting, simply a stack push and pop
> will do right.
No because you need to go back to user space to run the signal handler.
> Why do we restart the syscall. Is that a meaningful
> question. kindly explain me.
To avoid to have to write code as above taken from Advanced progrmming in
the UNIX environnement by R Stevens. pp275-279.
Tobias> A signal will interupte/restart a write only if no data has
Tobias> been written.
this is not true. In many contexts (such as writing a lot of data to a
pipe or socket) a signal can interrupt the call after part of the data
has been written; in which case the call will return how much data
_was_ written rather than failing with EINTR. SA_RESTART doesn't avoid
this.
--
Andrew.
comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
or <URL: http://www.whitefang.com/unix/>
Andrien,
IS that true? it will return how much data written r what. What type of
calls will return like this. Can you give me a example. I haven't seent
his behaviour. Curiously awaiting for your reply.