Describe how to use sanction such that a process receiving a

Describe how to use sanction such that a process receiving a signal can know the of the originating process of this signal.

Solution

Here is the Example for the implementation of the sigaction().

/* Example of using sigaction() to setup a signal handler with 3 arguments

* including siginfo_t.

*/

#include <stdio.h>

#include <unistd.h>

#include <signal.h>

#include <string.h>

static void hdl (int sig, siginfo_t *siginfo, void *context)

{

printf (\"Sending PID: %ld, UID: %ld\ \",

(long)siginfo->si_pid, (long)siginfo->si_uid);

}

int main (int argc, char *argv[])

{

struct sigaction act;

memset (&act, \'\\0\', sizeof(act));

/* Use the sa_sigaction field because the handles has two additional parameters */

act.sa_sigaction = &hdl;

/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */

act.sa_flags = SA_SIGINFO;

if (sigaction(SIGTERM, &act, NULL) < 0) {

perror (\"sigaction\");

return 1;

}

while (1)

sleep (10);

return 0;

}

 Describe how to use sanction such that a process receiving a signal can know the of the originating process of this signal.SolutionHere is the Example for the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site