summaryrefslogtreecommitdiff
path: root/userland/libc/signal/kill.c
blob: 4518b494a48ec6c76c28fd1f8a528e8803d8a11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <assert.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <syscall.h>
#include <unistd.h>

int kill(int pid, int sig) {
  char buffer[4096];
  snprintf(buffer, sizeof(buffer), "/proc/%d/signal", pid);
  int fd = open(buffer, O_WRITE);
  if (-1 == fd) {
    return -1;
  }
  if (-1 == dprintf(fd, "%d", sig)) {
    return -1;
  }
  assert(-1 != close(fd));
  return 0;
}