//main
Both of the "main" and "writer" codes written below are compiled and runnable programs with the same name. Draw the fork tree
in the program. (40) What will be the shell output when the program is run from the "main" shell? (60) (There is no error in the
programs. string-integer, integer-string conversion functions are given.)
#include <stdio.h>
#include <stdlib.h>
+ char *intTostr(int number) //convert function
int count=0;
int main()
{
count=0;
for(int i=0; i<3; i++)
{
int f1=fork();
if(f1==0)
{
char* argv[1];
argv[0]=intTostr(count);
argv[1]=NULL;
execve("writer",argv, NULL);
printf("%d. Writer Bitti\n",count);
}
else
{
count++;
wait(&f1);
printf("%d. Program\n",count);
}
}
return 0;
}
//writer
#include <stdio.h>
#include <stdlib.h>
+ int strToint(char* charnums) //convert function
int main(int argc, char* argv[], char** envp)
{
int count=strToint(argv[0]);
printf("%d. Writer\n",count);
for(int i=0; i<=count; count++)
printf(" %d\n",i);
return 0;
}
// shell print
//program
// fork tree
Pid:1000
Ppid:2345