Added utility getParentName() (name of parent process)
This commit is contained in:
		
							
								
								
									
										24
									
								
								utils.cpp
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								utils.cpp
									
									
									
									
									
								
							| @@ -2,6 +2,8 @@ | ||||
| #include "message_handler.h" | ||||
| #include "git/git_client.h" | ||||
|  | ||||
| #include "unistd.h" | ||||
|  | ||||
| #include <QFile> | ||||
| #include <QTextStream> | ||||
| #include <QDebug> | ||||
| @@ -169,3 +171,25 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2, | ||||
|  | ||||
|     return true; | ||||
| } | ||||
|  | ||||
|  | ||||
| QString Utils::getParentName() { // get name of parent process | ||||
|     QString ppid = QString("/proc/%1/status").arg(getppid()); | ||||
|     QFile f(ppid); | ||||
|     if (f.exists()) { | ||||
|         if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||||
|             QTextStream in(&f); | ||||
|             in.setCodec("UTF-8"); | ||||
|             while(!in.atEnd()) { | ||||
|                 // Name:   ATBQT | ||||
|                 QStringList line = in.readLine().split(':'); | ||||
|                 if (line.size() == 2) { | ||||
|                     if (line[0].trimmed() == "Name") { | ||||
|                         return line[1].trimmed(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return ""; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user