Question

- Write a C code, create a child process, and print out process IDs. Please ubuntu...

- Write a C code, create a child process, and print out process IDs. Please ubuntu gcc compiler

Thank you..
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

//program that creates a child process and print process ids
#include<sys/types.h>
#include<stdio.h>
//main function
int main()
{
int processId;
processId = fork();
if(processId < 0)
printf("fork error");
if(processId == 0)
{
printf("\nChild process");
printf("\nChild Process ID: %d", getpid());
printf("\nParent Process ID: %d", getppid());
execlp("/bin/ls",NULL);
exit(0);
}
else
{
wait(NULL);
printf("\nParent process");
printf("\nParent Process ID: %d", getpid());
printf("\nChild Process ID: %d", processId);
exit(0);
}
}

Output:

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
- Write a C code, create a child process, and print out process IDs. Please ubuntu...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT