title: Using execl commands
body: <p>I'm trying to understand the parts of the execl command. I'm new to programming in c and not very familiar with linux. I was told to execute a couple of statements using this command, and for the most part I think I understand it. </p>
  
  <p><code>execl(location here, followed by arguments, terminated by a null pointer)</code> </p>
  
  <p>I was tasked with executing the following using this command:</p>
  
  <ul>
  <li><p>A process status tree, ps --forest</p>
  
  <p><code>execl("/bin/ps", "ps", "--forest", (char*) NULL);</code> This works</p></li>
  <li><p>The Date and Time, date</p>
  
  <p><code>execl("/bin/date", "date", 0, (char*) NULL);</code> This works.</p></li>
  <li><p>The 'fortune' command</p>
  
  <p><code>execl("/usr/bin/fortune", "fortune", (char*) NULL);</code> This doesn't work.</p>
  
  <p><code>execl("/bin/fortune", "fortune", (char*) NULL);</code> This doesn't work.</p></li>
  </ul>
  
  <p>The main issue with the fortune command is that I'm either missing an argument, or I have the wrong location. I'm assuming it's the location because I can execute it with just "fortune" in the command line. I've searched for the correct location, but couldn't find any mention of it.</p>
  
  <p>Edit: Thanks to ojblass the location was verified to '/usr/bin/fortune', meaning my arguments must be incorrect.</p>
  
  <ul>
  <li><p>long directory listing code</p>
  
  <p><code>execl("/usr/bin/find", "find", "/", "-name", "date",  "-maxdepth", "3", "2&gt;", "/dev/null", (char *)NULL);</code> This doesn't work.</p></li>
  </ul>
  
  <p>Edit: Changed to:
  <code>execl("/usr/bin/find", "find", "/", "-name", "date",  "-maxdepth", "3", "2&gt;/dev/null", (char *)NULL);</code></p>
  
  <p>This is supposed to find files with the given name in them at a maximum depth of 3 from the root directory, then send all error messages to /dev/null. I'm pretty lost on this command.</p>
  
  <ul>
  <li>Code to install a signalhandler as code used to catch the signal.</li>
  </ul>
  
  <p>For this one, I'm not sure how to approach, but I know I need to take the argument they give, then pass that into the handler I've created. So something like:</p>
  
  <pre><code>`execl("/bin/I don't know this part maybe 'signal'?",cmd[1], (char*) NULL);`
  </code></pre>
  
  <p>Then pass it into <code>signal(cmd[1], sighandler);</code></p>
  
  <p>After writing the post, I'd say the part I'm primarily struggling with would be understanding the commands rather than the use of execl(). </p>
  
  <p>If you could either correct any place where I messed up, or give an explanation of the command, that would be greatly appreciated!</p>
  
  <p>Thanks!</p>
  
  <p>Edit: The solutions have been posted in the comments.</p>