-6

Create child process by using fork() function.

The parent process runs change content of the process by execl() function which run cat f1.c command.

child process runs a traceroute www.google.com command.

JustBaron
  • 2,319
  • 7
  • 25
  • 37
  • 1
    And what is your question? – Nico Haase May 17 '18 at 07:17
  • I am having a trouble solving the task , i know how to create child process with fork() function but i don't know how to solve the remaining. Could you help me? – European Academy May 17 '18 at 07:20
  • 2
    Welcome to Stack Overflow Where Developers Learn, Share, & Build Careers! All that has been posted is a program description. However, we need you to [ask a question](//stackoverflow.com/help/how-to-ask). We can't be sure what you want from us. Please [edit] your post to include a valid question that we can answer. Reminder: make sure you know [what is on-topic here](//stackoverflow.com/help/on-topic), asking us to write the program for you and suggestions are off-topic. – Ajay Brahmakshatriya May 17 '18 at 07:22
  • 1
    OK thank you . I'm new here. I don't know how this works. – European Academy May 17 '18 at 07:39

1 Answers1

0

Before asking questions here, please try it on your own and post what you have tried so far so we can guide you in the right direction. Also, it would be nice if you put more effort in asking better question. But to give you some guidance:

you can create child process by using fork. It returns an integer. If it is zero, that means you are in the child process. so you can do something like:

    int pid;
        if((pid=fork())==0){
          // you are in child process
          //use execl(constant char *path, constant char *commands); to run your commands
    }
    else {
          //whatever you need to do in the parent process
}

You can find about execl() here :https://www.systutorials.com/docs/linux/man/3-execl/ It is basically a way to run a command. The first argument is a constant char pointer which points to the shell that you want to run the command in ("/bin/sh" etc.). The next arguments are the command it self ("cd", "mydir" etc.) terminated with null.

execl("/bin/sh","cd","mydir",NULL); 
TheEngineer
  • 792
  • 6
  • 18