title: Qt: Failed to find out application pid when run from binary using script
body: <p>I have an aim to obtain the PID of application, when the latter runs.
  I wrote a simple function calls <code>pgrep</code> command:</p>
  
  <pre><code>QString Scriptlauncher::getAppProcessId() {
      QProcess p;
      QString programme("pgrep");
      QStringList args = QStringList() &lt;&lt; "app_name";
      p.start(programme, args);
      p.waitForReadyRead();
      QByteArray rdata = p.readAllStandardOutput();
      qDebug() &lt;&lt; "------------- script output rawdata is:" &lt;&lt; rdata;
      if (!rdata.isEmpty()) {
          QString pid(rdata);
          pid = pid.left(pid.length() -1); // cut '\n' symbol
          qWarning() &lt;&lt; "APPLICATION pid is" &lt;&lt; pid;
          return pid;
      }
      qWarning() &lt;&lt; "failed to find out PID";
      return ("-1");
  }
  </code></pre>
  
  <p>When I run the program directly from Qt or using a simple script (call it <code>execute.sh</code>; it exports all needed shared libs and then run app binary, - to run the app from terminal), the codeblock from above returns correct value:</p>
  
  <pre><code>user@host:/standalone_package/ execute.sh
  ------------- script output rawdata is: "21094\n"
  APPLICATION pid is "21094"
  </code></pre>
  
  <p>But when I run execute.sh from the valgrind heap profiler command, the function returns:</p>
  
  <pre><code>user@host:/standalone_package/ valgrind --tool=massif --trace-children=yes ./execute.sh
  ------------- script output rawdata is: ""
  failed to find out PID
  </code></pre>