Loading ...
Sorry, an error occurred while loading the content.

Re: [LINUX_Newbies] Prototype of "signal"

Expand Messages
  • Michael Kjorling
    ... Hash: SHA1 ... If you would have read a little further down, you would have found: If you re confused by the prototype at the top of this manpage, it
    Message 1 of 4 , Oct 1, 2002
    • 0 Attachment
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      On Oct 1 2002 06:03 -0000, Vikas wrote:

      > Dear all,
      > The man page of "signal" describes it as:
      > void (*signal(int sig, void(*func)(int)))(int) ;
      > I am unable to comprehend, please help me.
      > Please be as elaborate as you can.
      > Thanks.
      >
      > Vikas

      If you would have read a little further down, you would have found:

      If you're confused by the prototype at the top of this
      manpage, it may help to see it separated out thus:

      typedef void (*sighandler_t)(int);
      sighandler_t signal(int signum, sighandler_t handler);

      So, declare and implement a signal handler like:

      void my_sig_handler(int signal);

      and install it with (giving the appropriate signal):

      signal(SIGTERM, my_sig_handler);

      Simple enough?


      Michael Kjörling

      - --
      Michael Kjörling -- Programmer/Network administrator ^..^
      Internet: michael@... - Amateur Radio: SMØYBY \/
      PGP: 95f1 074d 336d f8f0 f297 6a5b 2aa3 7bfd 8a70 e33e
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.0.7 (GNU/Linux)
      Comment: Public key is at http://michael.kjorling.com/contact/pgp.html

      iD8DBQE9mYNaKqN7/Ypw4z4RAs82AJ0W/8w1pKJe8jIG2F17ND0eLQY8kACffpX/
      9+uA/Rd4a63FVzm+cUFrIGc=
      =idNu
      -----END PGP SIGNATURE-----
    • Jay Cornwall
      ... Okay. I m not sure what you want me to elaborate on exactly, but I ll explain the syntax. :) The signal() function takes as parameters: 1 - An integer 2 -
      Message 2 of 4 , Oct 1, 2002
      • 0 Attachment
        On Tuesday 01 Oct 2002 7:03 am, Vikas wrote:

        > The man page of "signal" describes it as:
        > void (*signal(int sig, void(*func)(int)))(int) ;
        > I am unable to comprehend, please help me.
        > Please be as elaborate as you can.

        Okay. I'm not sure what you want me to elaborate on exactly, but I'll explain
        the syntax. :)

        The signal() function takes as parameters:
        1 - An integer
        2 - A pointer to a function, containing your signal handler code

        The function which you pass as a parameter returns a ( void * ) and takes an
        integer as a parameter.

        The signal() function then returns a pointer to a function, which was the
        previously-installed signal handler (that you overrided with your new signal
        handler).

        If you want to make it easy to see, look at it this way:
        typedef void ( *func_ptr ) ( int )
        func_ptr *signal ( int, func_ptr * );

        Hrm. Not quite sure if this belongs on a Linux Newbies list, but there ya go.
        ;)

        Cheers,
        Jay

        --
        http://www.evilrealms.net/ - Systems Administrator
        http://www.ic.ac.uk/ - Imperial College, student and developer
      • Jay Cornwall
        ... Oops. It returns a void, not a void *. Sorry. Cheers, Jay -- http://www.evilrealms.net/ - Systems Administrator http://www.ic.ac.uk/ - Imperial College,
        Message 3 of 4 , Oct 1, 2002
        • 0 Attachment
          On Tuesday 01 Oct 2002 12:15 pm, Jay Cornwall wrote:

          > The function which you pass as a parameter returns a ( void * ) and takes
          > an integer as a parameter.

          Oops. It returns a void, not a void *. Sorry.

          Cheers,
          Jay

          --
          http://www.evilrealms.net/ - Systems Administrator
          http://www.ic.ac.uk/ - Imperial College, student and developer
        Your message has been successfully submitted and would be delivered to recipients shortly.