Question: I want to create a condition which executes the function only when all elements in the array are with status 3, if the array has an element with status 3 or different from 3 I should not execute the function.

I tried this code but doesn't work when I have element with status 3 ore different status.

```
   goToPeople(): void {
    const selectedItems = this.ms.selectedItems;
      selectedItems.forEach(item => {
        if (item.status !== 3){
          console.log('nonnnnnn');
        }else{
          console.log('yesss');
          //my function
        }
      });
  }

```

This is JSON:

```
[
    {
        "date": "2021-10-14T16:48:05+00:00",
        "status": 3,
        "name": "HRDD",
        "id": "ab8d4bd7"
    },
    {
        "date": "2021-10-14T16:55:05+00:00",
        "status": 2,
        "name": "ddfgdfgd",
        "id": "adfgdfgdf45"
    }
]

```

Answer: 
The `signal()` function is problematic because of a history of implementations with different details. According to [its Linux manual page](https://man7.org/linux/man-pages/man2/signal.2.html):

> 
> The only portable use of `signal()` is to set a signal's disposition to `SIG_DFL` or `SIG_IGN`. The semantics when using `signal()` to establish a signal handler vary across systems (and POSIX.1 explicitly permits this variation); **do not use it for this purpose**.
> 
> 
> 

(Emphasis in the original)

Instead of `signal()`, you should be using `sigaction()`:

```
  struct sigaction sa = { .sa_handler = catchSignal };

  if (SIG_ERR == sigaction(SIGTERM, &sa, NULL))

```

Note that among the fields of a `struct sigaction` is `sa_flags`, a bitmask with which you can select among the various behaviors historically implemented by different versions of `signal()`. In particular, if you do not include the `SA_RESTART` flag, as the above indeed does not, then you should not see system calls automatically resume when interrupted by a signal (except for those few that are explicitly specified to do so).
When you `strace` your program, you see that signal() functions sets SA\_RESTART flag for the signal:

```
rt_sigaction(SIGTERM, {sa_handler=0x562f2a8c3249, sa_mask=[TERM], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb504d2d210}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0

```

meaning, that the open() syscall will be automatically restarted after handling the signal.

You can use [sigaction()](https://man7.org/linux/man-pages/man2/sigaction.2.html) to have more fine-grained control over signal handling and not set the SA\_RESTART:

```
struct sigaction sa;
memset (&sa, 0, sizeof (sa));
sa.sa_handler = catchSignal;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
if (sigaction (SIGTERM, &sa, NULL) == -1) {
  perror("sigaction");
  return -1;
}

```