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).
you can use `O_NONBLOCK` in which case `open()` will return immediately, and you will block as soon as you `fcntl(2)` cancelling the `O_NONBLOCK`.

Read the man page, as probably you have some way to make `open(2)` return `-1` and `errno` equal to `EINTR`. But the normal usage is what has been described, the call is reissued, so the signal handler doesn't make the calll to be interrupted (much code depends on this behaviour). I'm not sure about this, but I think only `pause(2)` and `select(2)` and friends are interrupted (and return) when a non-ignored signal is received.

Is worth noting that only the thread that is blocked in an interruptible call and receives the signal is awaken and the call interrupted, and the thread receiving the interrupt can be any of the ones you have started in your process.