Hello ,
im using this easy script :
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
void main(void) {
printf("Bonjour1 ");
int pid = fork();
printf("pid %d.\n", pid);
if (pid == 0) {
printf("I am the child.%d.\n", getpid());
}
if (pid > 0) {
printf("I am the parent, %d.\n", getpid());
}
if (pid < 0) {
perror("In fork():");
}
exit(0);
}
The result is :
Bonjour1 pid 5447.
I am the parent, 5446.
Bonjour1 pid 0.
I am the child.5447.
All its OK. but i wanted to insert a line break after the world "bonjour" by using (\n)
so when i replace printf("Bonjour1 "); by printf("Bonjour1 \n"); i have this result :
Bonjour1
pid 5503.
I am the parent, 5502.
pid 0.
I am the child.5503.
I dont have the second "bonjour" of children process.
Can you explain to me why ?
thanks
im using this easy script :
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
void main(void) {
printf("Bonjour1 ");
int pid = fork();
printf("pid %d.\n", pid);
if (pid == 0) {
printf("I am the child.%d.\n", getpid());
}
if (pid > 0) {
printf("I am the parent, %d.\n", getpid());
}
if (pid < 0) {
perror("In fork():");
}
exit(0);
}
The result is :
Bonjour1 pid 5447.
I am the parent, 5446.
Bonjour1 pid 0.
I am the child.5447.
All its OK. but i wanted to insert a line break after the world "bonjour" by using (\n)
so when i replace printf("Bonjour1 "); by printf("Bonjour1 \n"); i have this result :
Bonjour1
pid 5503.
I am the parent, 5502.
pid 0.
I am the child.5503.
I dont have the second "bonjour" of children process.
Can you explain to me why ?
thanks