title: Execute ssh command with system()
body: <p>I have a C++ application (under linux) which open a ssh reverse tunnel. This works well. But i have some trouble to close the connection. 
  The close command will work like it should when i start the application from the command line, but when i start the application from a cron job in background, the connection will not be closed.</p>
  
  <p>Here my code:</p>
  
  <p>Open connection:</p>
  
  <pre><code>std::string cmd = "ssh -o StrictHostKeyChecking=no -f -N -T -M -R 8003:192.168.0.1:8001 -R 8007:192.168.0.1:8005 -R 22222:localhost:22 sshService";
  system(cmd.c_str());
  </code></pre>
  
  <p>To close the connection i use:</p>
  
  <pre><code>std::string cmd = "ssh -T -O exit sshService";
  system(cmd.c_str());
  </code></pre>
  
  <p>My host configuration is:</p>
  
  <pre><code>Host sshService
      HostName www.addressOfServer.com
      User sshUser
      ControlPersist 4h
      ControlPath ~/.ssh/sshService.ctl
      IdentityFile /home/user/sshUser
  </code></pre>
  
  <p>Are there some ideas, what i make wrong? Or some ideas how i can find out the problem?</p>