diff --git a/src/ProcessInfo.h b/src/ProcessInfo.h index b7b4f5659..ff2500d0f 100644 --- a/src/ProcessInfo.h +++ b/src/ProcessInfo.h @@ -121,6 +121,10 @@ public: /*** * Returns the id of the current foreground process * + * NOTE: Using the foregroundProcessGroup() method of the Pty + * instance associated with the terminal of interest is preferred + * over using this method. + * * @param ok Set to true if the foreground process id was read successfully or false otherwise */ int foregroundPid(bool* ok) const; diff --git a/src/Pty.cpp b/src/Pty.cpp index 92721df5c..c4dd85157 100644 --- a/src/Pty.cpp +++ b/src/Pty.cpp @@ -258,4 +258,16 @@ void Pty::lockPty(bool lock) resume(); } +int Pty::foregroundProcessGroup() const +{ + int pid = tcgetpgrp(pty()->masterFd()); + + if ( pid != -1 ) + { + return pid; + } + + return 0; +} + #include "Pty.moc" diff --git a/src/Pty.h b/src/Pty.h index d47a1d358..5d86e113c 100644 --- a/src/Pty.h +++ b/src/Pty.h @@ -57,6 +57,8 @@ Q_OBJECT void setSize(int lines, int cols); void setErase(char erase); + int foregroundProcessGroup() const; + public Q_SLOTS: void useUtf8(bool on); void lockPty(bool lock); diff --git a/src/Session.cpp b/src/Session.cpp index d323c8def..ccfd110ce 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -877,7 +877,10 @@ void Session::setSize(QSize size) emit resizeSession(this, size); } - +int Session::foregroundPid() const +{ + return _shellProcess->foregroundProcessGroup(); +} int Session::sessionPid() const { return _shellProcess->pid(); diff --git a/src/Session.h b/src/Session.h index 9d8f63df0..9589da0c3 100644 --- a/src/Session.h +++ b/src/Session.h @@ -205,6 +205,12 @@ public: * This is the id used by the system API to refer to the process. */ int sessionPid() const; + + /** + * Returns the process id of the terminal's foreground process. + */ + int foregroundPid() const; + void enableFullScripting(bool b); void startZModem(const QString &rz, const QString &dir, const QStringList &list); diff --git a/src/SessionController.cpp b/src/SessionController.cpp index fd67e7a3b..0c8944c0a 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -101,7 +101,6 @@ void SessionController::snapshot() { qDebug() << "session" << _session->title() << "snapshot"; - bool ok = false; ProcessInfo* process = 0; ProcessInfo* snapshot = ProcessInfo::newInstance(_session->sessionPid()); @@ -109,8 +108,8 @@ void SessionController::snapshot() // use foreground process information if available // fallback to session process otherwise - int pid = snapshot->foregroundPid(&ok); - if ( ok ) + int pid = _session->foregroundPid(); //snapshot->foregroundPid(&ok); + if ( pid != 0 ) { process = ProcessInfo::newInstance(pid); process->update(); @@ -118,6 +117,7 @@ void SessionController::snapshot() else process = snapshot; + bool ok = false; QString title; if ( process->name(&ok) == "ssh" && ok ) { @@ -152,8 +152,8 @@ KUrl SessionController::url() const bool ok = false; // check if foreground process is bookmark-able - int pid = info->foregroundPid(&ok); - if ( ok ) + int pid = _session->foregroundPid(); + if ( pid != 0 ) { qDebug() << "reading session process = " << info->name(&ok);