20#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
39#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
40 pid_t pid = GetPIDbyName(qPrintable(m_name));
43 return (pid != -1 && pid != -2);
49#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
50bool ProcessInfo::IsNumeric(
const char* ccharptr_CharacterList)
const
52 for (; *ccharptr_CharacterList; ccharptr_CharacterList++) {
53 if (*ccharptr_CharacterList < '0' || *ccharptr_CharacterList >
'9') {
61pid_t ProcessInfo::GetPIDbyName(
const char* cchrptr_ProcessName)
const
63 char chrarry_CommandLinePath[260] ;
64 char chrarry_NameOfProcess[300] ;
65 char* chrptr_StringToCompare = NULL ;
66 pid_t pid_ProcessIdentifier = (pid_t) - 1 ;
67 struct dirent* de_DirEntity = NULL ;
68 DIR* dir_proc = NULL ;
70 dir_proc = opendir(
"/proc/") ;
71 if (dir_proc == NULL) {
72 perror(
"Couldn't open the /proc/ directory") ;
77 while ((de_DirEntity = readdir(dir_proc))) {
79 if (de_DirEntity->d_type == DT_DIR) {
80 if (IsNumeric(de_DirEntity->d_name)) {
81 strcpy(chrarry_CommandLinePath,
"/proc/") ;
82 strcat(chrarry_CommandLinePath, de_DirEntity->d_name) ;
83 strcat(chrarry_CommandLinePath,
"/cmdline") ;
84 FILE* fd_CmdLineFile = fopen(chrarry_CommandLinePath,
"rt") ;
86 int r = fscanf(fd_CmdLineFile,
"%20s", chrarry_NameOfProcess) ;
88 fclose(fd_CmdLineFile);
94 if (strrchr(chrarry_NameOfProcess,
'/')) {
95 chrptr_StringToCompare = strrchr(chrarry_NameOfProcess,
'/') + 1 ;
98 chrptr_StringToCompare = chrarry_NameOfProcess ;
104 if (!strcmp(chrptr_StringToCompare, cchrptr_ProcessName)) {
105 pid_ProcessIdentifier = (pid_t) atoi(de_DirEntity->d_name) ;
107 return pid_ProcessIdentifier ;
116 return pid_ProcessIdentifier ;
ProcessInfo(const QString &name)