Created
April 27, 2018 14:45
-
-
Save cassianomaia/f8b2fc5d9d844f5c74399bcf37294206 to your computer and use it in GitHub Desktop.
Syscall computer test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
//#include <linux/linkage.h> | |
#include <linux/sched.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/wait.h> | |
#include <sys/types.h> | |
#include <string.h> | |
pid_t vetor[10]; | |
void salvaNumero(int j, pid_t pid1){ | |
vetor[j] = pid1; | |
if (vetor[j]%2 == 0){ | |
printf("O processo filho com o pid %d foi morto\n", vetor[j]); | |
kill(vetor[j], SIGKILL); | |
} | |
} | |
void sys_callkpar(pid_t pid) { | |
int i; | |
pid_t pidteste, aux; | |
pid_t pidpai; | |
int status = 0; | |
pidpai = pid; | |
memset(vetor, 0,sizeof(vetor)); | |
for (i = 0; i < 10; i++){ | |
pidteste = fork(); | |
if ( pidteste == 0){ | |
aux = getpid(); | |
salvaNumero(i, aux); | |
_exit(0); | |
} | |
} | |
} | |
int main(){ | |
pid_t pidaux; | |
pidaux = getpid(); | |
sys_callkpar(pidaux); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment