Get pid and ppid

This commit is contained in:
Ximi1970
2020-02-25 23:05:20 +01:00
parent df6d128bd7
commit 6fa06ca74e
6 changed files with 68 additions and 0 deletions

View File

@@ -14,10 +14,28 @@ Close window
https://docs.microsoft.com/en-us/windows/win32/learnwin32/closing-the-window
Get processes
(EnumProcesses function)
https://www.qtcentre.org/threads/46145-Get-All-Running-Process-Win32
X11
==========================================
Get processes (parent pid, pid and arguments)
ps -eo ppid,pid,args
qint64 QCoreApplication::applicationPid() to get systrayx pid -> parent pid -> tb window.
ps -p [PID] -o ppid
Bash
xwininfo -tree -root

View File

@@ -1,5 +1,18 @@
#include "preferences.h"
/*
* Local includes
*/
/*
* System includes
*/
/*
* Qt includes
*/
/**
* @brief Preferences. Constructor.
*/

View File

@@ -5,6 +5,7 @@
/*
* System includes
*/
#include <unistd.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
@@ -23,6 +24,15 @@ WindowCtrlUnix::WindowCtrlUnix( QObject *parent ) : QObject( parent )
}
/*
* Get the parent pid of SysTray-X, TB hopefully
*/
qint64 WindowCtrlUnix::getPpid()
{
return getppid();
}
/*
* Find window(s) by title
*/

View File

@@ -110,6 +110,13 @@ class WindowCtrlUnix : public QObject
*/
explicit WindowCtrlUnix( QObject *parent = nullptr );
/**
* @brief getPpid. Get the parent process id.
*
* @return The ppid
*/
qint64 getPpid();
/**
* @brief findWindow. Find window with title.
*

View File

@@ -3,6 +3,7 @@
*/
#include <QWidget>
#include <QWindow>
#include <QCoreApplication>
/*
* Main include
@@ -35,6 +36,12 @@ WindowCtrl::WindowCtrl( Preferences* pref, QObject *parent ) :
* Initialize
*/
m_minimize_hide = m_pref->getMinimizeHide();
/*
* Get pids
*/
m_pid = QCoreApplication::applicationPid();
m_ppid = getPpid();
}
@@ -70,6 +77,9 @@ void WindowCtrl::slotWindowTest3()
// Do something.
emit signalConsole( QString( "Pid %1" ).arg( m_pid ) );
emit signalConsole( QString( "Ppid %1" ).arg( m_ppid ) );
emit signalConsole("Test 3 done");
}

View File

@@ -95,6 +95,16 @@ class WindowCtrl : public QObject
*/
Preferences* m_pref;
/**
* @brief m_pid. SysTray-X process pid.
*/
qint64 m_pid;
/**
* @brief m_ppid. SysTray-X parent process pid.
*/
qint64 m_ppid;
/**
* @brief m_tb_window. Pointer to the TB window.
*/