fork()

#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#define MAX_COUNT 200
#define BUF_SIZE 100

void main(void)
{
pid_t pid;
int i;
char buf[BUF_SIZE];

 fork\(\);
 pid = getpid\(\);
 for \(i = 1; i &lt;= MAX_COUNT; i\+\+\) \{
      sprintf\(buf, "This line is from pid %d, value = %d\\n", pid, i\);
      write\(1, buf, strlen\(buf\)\);
 \} 

}

if i execute the code the process would be link

Parent Child

main() main()
{ {
fork(); fork();
pid=.. pid=...
} }

but ,do both processes execute the while loop seperately
can i get the result like that

parent 1 ...............200

child 1...............200

try Programming in C

This has more to do with the OS than C. What you did is to make two independent processes. Based on your output it looks like only one process can run on the cpu at one time.

It's like driving a car. Only one person can be in the driver's seat at one time. Once one of the processes gets into the driver's seat the OS is letting it staty there for a while. Long enough to finish the loop anyway.