Upon receiving a signal, is it possible to know the PID of the sender?

Hi all,

the subject say it all.

I know how to catch the it using Signal.trap, the thing is that
I want to perform different action based on which process sent
the signal.

In my case there's no relation between sender and receiver process
(they are not in parent-child relation).

I know that in C there's a way to do it.

I've searched quite a bit but I didn't find anything equivalent for
the Ruby world.

Thanks in advance

sick

Hi all,

the subject say it all.

I know how to catch the it using Signal.trap, the thing is that
I want to perform different action based on which process sent
the signal.

Not currently...

I know that in C there's a way to do it.

Maybe SA_SIGACTION is common enough nowadays that Ruby can use it;
at least for POSIX systems.

However it's still racy: there's the unlikely case where the original
sending PID could die and be recycled by a new process by the time the
receiver receives a signal (consider the receiver is suspended or
otherwise blocked for a while).

···

"sickpig@gmail.com" <sickpig@gmail.com> wrote:

Quoting sickpig@gmail.com (sickpig@gmail.com):

I know how to catch the it using Signal.trap, the thing is that
I want to perform different action based on which process sent
the signal.

In my case there's no relation between sender and receiver process
(they are not in parent-child relation).

I know that in C there's a way to do it.

I know of no way under Linux. When you intercept the signal (see man
signal) the function you provide just receives the signal type -
nothing else.

If you know a way under C/Posix I'd be curious to know about it.

Carlo

···

Subject: Upon receiving a signal, is it possible to know the PID of the sender?
  Date: mer 01 lug 15 11:15:00 +0200

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

oh right, I didn't think about this.

In any case in my particular set-up I think I'm safe cause I know how
the real sender will behave upon a USR2 signal.

thanks

···

On Wed, Jul 1, 2015 at 11:37 AM, Eric Wong <normalperson@yhbt.net> wrote:

"sickpig@gmail.com" <sickpig@gmail.com> wrote:

I know how to catch the it using Signal.trap, the thing is that
I want to perform different action based on which process sent
the signal.

Not currently...

I know that in C there's a way to do it.

Maybe SA_SIGACTION is common enough nowadays that Ruby can use it;
at least for POSIX systems.

However it's still racy: there's the unlikely case where the original
sending PID could die and be recycled by a new process by the time the
receiver receives a signal (consider the receiver is suspended or
otherwise blocked for a while).

sigaction can read it optionally, but it's not very common
Also, signalfd in Linux

···

"Carlo E. Prelz" <fluido@fluido.as> wrote:

Quoting sickpig@gmail.com (sickpig@gmail.com):
> I know that in C there's a way to do it.

I know of no way under Linux. When you intercept the signal (see man
signal) the function you provide just receives the signal type -
nothing else.

If you know a way under C/Posix I'd be curious to know about it.

sure:

to make a long story short: use sigaction rather than signal as
handler, as Eric already pointed out.

···

On Wed, Jul 1, 2015 at 11:26 AM, Carlo E. Prelz <fluido@fluido.as> wrote:

        Subject: Upon receiving a signal, is it possible to know the PID of the sender?
        Date: mer 01 lug 15 11:15:00 +0200

Quoting sickpig@gmail.com (sickpig@gmail.com):

I know how to catch the it using Signal.trap, the thing is that
I want to perform different action based on which process sent
the signal.

In my case there's no relation between sender and receiver process
(they are not in parent-child relation).

I know that in C there's a way to do it.

I know of no way under Linux. When you intercept the signal (see man
signal) the function you provide just receives the signal type -
nothing else.

If you know a way under C/Posix I'd be curious to know about it.