Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/wait.h>
- int create_new_child(char *text, char *filename);
- int main(){
- int nb_child = 5;
- int pid_array[nb_child];
- for(int i = 0; i < nb_child; i++){
- pid_array[i] = create_new_child("test" , "toto.txt");
- printf("%d\n", pid_array[i]);
- }
- }
- int create_new_child(char *text, char *filename){
- int pid;
- int ret_pid;
- FILE* fp = NULL;
- fp = fopen(filename, "w+");
- pid = fork();
- if(pid != 0){
- printf("%s\n", text);
- fputs(text, fp);
- }
- ret_pid = getpid();
- return ret_pid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement