2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SystemServicesIf
19 /// \brief This file supports the System Manager OS process abstraction.
21 ///////////////////////////////////////////////////////////////////////////////
23 * @file ss_system_process.h
25 /** @addtogroup BaseSystem
28 /** @addtogroup system_service
32 /** @addtogroup interface_unified
33 * @ingroup system_service
36 #ifndef __Process_H__ // NOLINT (build/header_guard)
40 #include <native_service/frameworkunified_types.h>
41 #include <native_service/cl_process.h>
42 #include <system_service/ss_system_types.h>
48 const long lProcess_VALIDATION_VALUE = 2198645; // NOLINT (runtime/int)
49 // Used to define a unique value that represents this class.
50 // This value is stored in the object when the object is created,
51 // and cleared when the object is destroyed.
53 const int iProcess_DEFAULT_PROCESS_PRIORITY = 10;
54 // This is the default process priority that all new processes will use.
56 const int iProcess_MAXIMUM_PROCESS_PRIORITY = 60;
57 // This is the maximum priority a process can have
59 const long iProcess_DEFAULT_PROCESS_FLAGS = POSIX_SPAWN_SETSCHEDULER // NOLINT (runtime/int)
60 | POSIX_SPAWN_SETSCHEDPARAM;
62 // This flag field is a bit wise OR of spawning options to use when a process
65 const int iProcess_MAXIMUM_NUMBER_OF_PROCESS_ARGUMENTS = 25;
66 // This is the maximum number of command line (i.e. argv[]) arguments we can
67 // send to a process. This includes; exectuable file name + process arguments + NULL
69 const int iProcess_MAXIMUM_PROCESS_NAME_LENGTH = 32;
70 // This is the maximum number of characters that a process name can be in bytes.
74 typedef std::map<SS_String, Process *> ProcessMap;
78 * \~english @brief OS process
79 * \~english @par Brief Introduction
80 * This class is the System Manager OS process abstraction.
85 enum eProcessLoadMode {
86 WAIT, // The invoked program is loaded into available memory, is executed,
87 // and then the original program resumes execution.
88 NOWAIT, // Causes the current program to execute concurrently with the new child process.
91 enum eProcessSchedulingPolicy {
92 FIFO, // A fixed priority scheduler in which the highest ready process runs until it
93 // blocks or is preempted by a higher priority process.
94 ROUND_ROBIN, // The same as FIFO, except processes at the same priority level time-slice.
95 OTHER // A general time sharing scheduler in which a process decays in priority if it
96 // consumes too much processor before blocking. It reverts to its default priority
97 // when it blocks. Should it fail to run over a 2 second period and it has decayed
98 // then it's boosted one priority level up to a maximum of its default priority.
101 /////////////////////////////////////////////////////////////////////////////////////
103 /// \~english @par Summary
104 /// - Default Constructor, called when the class is instantiated.
105 /// \~english @param [in] - cpu_assign
106 /// - Assignment information of CPU.
107 /// \~english @retval None
108 /// \~english @par Preconditions
109 /// -no preconditions
110 /// \~english @par Change of the internal state
111 /// - initialize all var
112 /// \~english @par Causes of failures
114 /// \~english @par Classification
116 /// \~english @par Type
118 /// \~english @par Detail
119 /// - initialize all var in class as default value
120 /// \~english @see ~Process
121 ////////////////////////////////////////////////////////////////////////////////////
122 Process(int cpu_assign = 0x0);
124 /////////////////////////////////////////////////////////////////////////////////////
126 /// \~english @par Summary
127 /// - Copy Constructor
128 /// \~english @param [in] - p_rhs_i
129 /// - Process - Reference to a Process that you want to copy.
130 /// \~english @retval None
131 /// \~english @par Preconditions
132 /// -no preconditions
133 /// \~english @par Change of the internal state
135 /// \~english @par Causes of failures
137 /// \~english @par Classification
139 /// \~english @par Type
141 /// \~english @par Detail
142 /// - Used to create an object and copy another object to the new object.
143 /// \~english @see ~Process
144 ////////////////////////////////////////////////////////////////////////////////////
145 Process(const Process& p_rhs_i);
147 /////////////////////////////////////////////////////////////////////////////////////
148 /// \ingroup ~Process
149 /// \~english @par Summary
150 /// - Destructor function
151 /// \~english @param None
152 /// \~english @retval None
153 /// \~english @par Preconditions
154 /// -no preconditions
155 /// \~english @par Change of the internal state
156 /// - set m_lValidationTag with 0
157 /// \~english @par Causes of failures
159 /// \~english @par Classification
161 /// \~english @par Type
163 /// \~english @par Detail
164 /// - Destructor, called when the object is destroyed.\n
165 /// set m_lValidationTag with 0 and kill process.
166 /// \~english @see Process
167 ////////////////////////////////////////////////////////////////////////////////////
170 /////////////////////////////////////////////////////////////////////////////////////
171 /// \ingroup operator=
172 /// \~english @par Summary
173 /// - Assignment Operator
174 /// \~english @param [in]
175 /// \~english @retval Process - New Process object
176 /// \~english @par Preconditions
177 /// -no preconditions
178 /// \~english @par Change of the internal state
180 /// \~english @par Causes of failures
182 /// \~english @par Classification
184 /// \~english @par Type
186 /// \~english @par Detail
187 /// - Assignment Operator, called when one object is assigned to another object.
188 /// \~english @see None
189 ////////////////////////////////////////////////////////////////////////////////////
190 Process& operator=(const Process& p_rhs_i);
192 /////////////////////////////////////////////////////////////////////////////////////
193 /// \ingroup GetProcessId
194 /// \~english @par Summary
196 /// \~english @param None
197 /// \~english @retval process pid - the process pid of the process running.
198 /// \~english @par Preconditions
199 /// -no preconditions
200 /// \~english @par Change of the internal state
202 /// \~english @par Causes of failures
204 /// \~english @par Classification
206 /// \~english @par Type
208 /// \~english @par Detail
209 /// - This method will return to the caller the PosixBasedOS001 Specific Process ID.
210 /// \~english @see None
211 ////////////////////////////////////////////////////////////////////////////////////
212 int const GetProcessId(void) {
213 return static_cast<int>(m_tProcessId);
216 /////////////////////////////////////////////////////////////////////////////////////
217 /// \ingroup SetCallingArgumentList
218 /// \~english @par Summary
219 /// - This method will set the calling argument list that this object represents
220 /// \~english @param [in] p_pcArgv_i
221 /// - const char *[] - Pointer to array of null terminated parameter list.
222 /// \~english @param [in] p_iArgc_i
223 /// - const int - - Number of arguments in the array passed.
224 /// \~english @retval None
225 /// \~english @par Preconditions
226 /// -no preconditions
227 /// \~english @par Change of the internal state
228 /// - put the new arguments into m_strlstArgv
229 /// \~english @par Causes of failures
231 /// \~english @par Classification
233 /// \~english @par Type
235 /// \~english @par Detail
236 /// - Set the executable filename first. This is always the 1st argument
237 /// - in the argument list. Then set the argument list for the process
238 /// - which is held in m_strlstArgv.
239 /// - First make sure that the argument list is empty.
240 /// - Once empty, put the new arguments into the list
241 /// \~english @see None
242 ////////////////////////////////////////////////////////////////////////////////////
243 void SetCallingArgumentList(const char *p_pcArgv_i[], const int p_iArgc_i);
245 /////////////////////////////////////////////////////////////////////////////////////
246 /// \ingroup SetCallingArgumentList
247 /// \~english @par Summary
248 /// - This method will set the calling argument list that this object represents.
249 /// \~english @param [in] p_strlstParameters_i
250 /// - const StringList& - String list of arguments that will be used to start.
251 /// \~english @retval None.
252 /// \~english @par Preconditions
253 /// - no preconditions.
254 /// \~english @par Change of the internal state
255 /// - set m_strlstArgv with p_strlstParameters_i.
256 /// \~english @par Causes of failures
258 /// \~english @par Classification
260 /// \~english @par Type
262 /// \~english @par Detail
263 /// - if p_strlstParameters_i is not empty,then clear m_strlstArgv \n
264 /// - and set m_strlstArgv with p_strlstParameters_i.
265 /// \~english @see None
266 ////////////////////////////////////////////////////////////////////////////////////
267 void SetCallingArgumentList(const StringList& p_strlstParameters_i);
269 /////////////////////////////////////////////////////////////////////////////////////
270 /// \ingroup GetExecutableFileName
271 /// \~english @par Summary
272 /// - Get executable file name
273 /// \~english @param None
274 /// \~english @retval Pointer
275 /// - Points to SS_String object that holds the path and executable file name for this process
276 /// \~english @par Preconditions
277 /// -no preconditions
278 /// \~english @par Change of the internal state
280 /// \~english @par Causes of failures
282 /// \~english @par Classification
284 /// \~english @par Type
286 /// \~english @par Detail
287 /// - This method will return a pointer to the executable filename that this object represents
288 /// \~english @see None
289 ////////////////////////////////////////////////////////////////////////////////////
290 const char * const GetExecutableFileName() {
291 return m_strFile.c_str();
294 /////////////////////////////////////////////////////////////////////////////////////
295 /// \ingroup GetProcessReturnCode
296 /// \~english @par Summary
297 /// - This function will return the processes exit/return code.
298 /// \~english @param None
299 /// \~english @retval process exit code - Code for the last process to execute
300 /// \~english @par Preconditions
301 /// -no preconditions
302 /// \~english @par Change of the internal state
303 /// - set m_iReturnCode with WEXITSTATUS(iProcessReturn)
304 /// \~english @par Causes of failures
306 /// \~english @par Classification
308 /// \~english @par Type
310 /// \~english @par Detail
311 /// - This function will return the processes exit/return code.\n
312 /// This is not the value of ERRNO as returned by GetLastPosixBasedOS001ErrorCode().
313 /// \~english @see None
314 ////////////////////////////////////////////////////////////////////////////////////
315 int GetProcessReturnCode(void);
317 /////////////////////////////////////////////////////////////////////////////////////
318 /// \ingroup SetSchedulingPolicy
319 /// \~english @par Summary
320 /// - This method will change the scheduling policy for the process this object represents.
321 /// \~english @param [in] p_eSchedulingPolicy_i
322 /// - const eProcessSchedulingPolicy - Scheduling Policy for this process
324 /// - eProcessSchedulingPolicy
326 /// - enum eProcessSchedulingPolicy {
327 /// FIFO, A fixed priority scheduler in which the highest ready process runs until it\n
328 /// blocks or is preempted by a higher priority process.
329 /// ROUND_ROBIN, The same as FIFO, except processes at the same priority level time-slice.
330 /// OTHER A general time sharing scheduler in which a process decays in priority if it\n
331 /// consumes too much processor before blocking. It reverts to its default priority\n
332 /// when it blocks. Should it fail to run over a 2 second period and it has decayed\n
333 /// then it's boosted one priority level up to a maximum of its default priority.
336 /// \~english @retval None
337 /// \~english @par Preconditions
338 /// -no preconditions
339 /// \~english @par Change of the internal state
340 /// -If the result of function is not 0,then set m_iErrorCode with errno
341 /// - else set m_iErrorCode with 0.
342 /// \~english @par Causes of failures
344 /// \~english @par Classification
346 /// \~english @par Type
348 /// \~english @par Detail
349 /// - Attempt to change the scheduling policy for the process that this object
350 /// represents. If the change fails, restore the previous settings.
351 /// \~english @see None
352 ////////////////////////////////////////////////////////////////////////////////////
353 void SetSchedulingPolicy(
354 const eProcessSchedulingPolicy p_eSchedulingPolicy_i);
356 /////////////////////////////////////////////////////////////////////////////////////
357 /// \ingroup GetSchedulingPolicy
358 /// \~english @par Summary
359 /// - Get currently configured scheduling policy
360 /// \~english @param None
361 /// \~english @retval FIFO - A fixed priority scheduler in which the highest ready process runs until it\n
362 /// blocks or is preempted by a higher priority process.
363 /// \~english @retval ROUND_ROBIN - The same as FIFO, except processes at the same priority level time-slice.
364 /// \~english @retval OTHER - A general time sharing scheduler in which a process decays in priority if it\n
365 /// consumes too much processor before blocking. It reverts to its default priority\n
366 /// when it blocks. Should it fail to run over a 2 second period and it has decayed\n
367 /// then it's boosted one priority level up to a maximum of its default priority.
368 /// \~english @par Preconditions
369 /// -no preconditions
370 /// \~english @par Change of the internal state
371 /// - If the result of calling function sched_getscheduler(m_tProcessId) is -1
372 /// then set m_iErrorCode with errno
373 /// \~english @par Causes of failures
375 /// \~english @par Classification
377 /// \~english @par Type
379 /// \~english @par Detail
380 /// - This method will return to the caller the currently configured process scheduling policy.
381 /// If the result of calling function sched_getscheduler(m_tProcessId) is -1,
382 /// then return ROUND_ROBIN.
383 /// \~english @see None
384 ////////////////////////////////////////////////////////////////////////////////////
385 eProcessSchedulingPolicy const GetSchedulingPolicy(void);
387 /////////////////////////////////////////////////////////////////////////////////////
388 /// \ingroup SetPriority
389 /// \~english @par Summary
390 /// - This method will change the priority for the process this object represents.
391 /// \~english @param [in] p_iPriority_i
392 /// - int - Priority of the process
393 /// \~english @retval None
394 /// \~english @par Preconditions
395 /// -no preconditions
396 /// \~english @par Change of the internal state
397 /// - If the result of function sched_setparam(m_tProcessId, &cur_sch_params)\n
398 /// is -1,then set m_iErrorCode with errno, else set m_iErrorCode with 0.
399 /// \~english @par Causes of failures
401 /// \~english @par Classification
403 /// \~english @par Type
405 /// \~english @par Detail
406 /// - Using p_iPriority_i to change the priority for the process\n
407 /// this object represents,if the result of function \n
408 /// sched_setparam(m_tProcessId, &cur_sch_params) is -1
409 /// m_iErrorCode will be seted with errno,else be seted with 0
410 /// \~english @see None
411 ////////////////////////////////////////////////////////////////////////////////////
412 void SetPriority(const int p_iPriority_i);
414 /////////////////////////////////////////////////////////////////////////////////////
415 /// \ingroup SetPriority Notice:Can't find the body of this function
416 /// \~english @par Summary
417 /// - This method will change the priority for the specified process ID.
418 /// \~english @param [in] p_iPid_i
419 /// - pid_t - PID of the process to change the priority
420 /// \~english @param [in] p_iPriority_i
421 /// - int - Priority of the process
422 /// \~english @retval None
423 /// \~english @par Preconditions
424 /// -no preconditions
425 /// \~english @par Change of the internal state
427 /// \~english @par Causes of failures
429 /// \~english @par Classification
431 /// \~english @par Type
433 /// \~english @par Detail
435 /// \~english @see None
436 ////////////////////////////////////////////////////////////////////////////////////
437 void SetPriority(const pid_t p_iPid_i, const int p_iPriority_i);
439 /////////////////////////////////////////////////////////////////////////////////////
440 /// \ingroup IncreasePriorityByOne
441 /// \~english @par Summary
442 /// - This method will increase the priority for the process this\n
443 /// object represents by one.
444 /// \~english @param None
445 /// \~english @retval None
446 /// \~english @par Preconditions
447 /// -no preconditions
448 /// \~english @par Change of the internal state
450 /// \~english @par Causes of failures
452 /// \~english @par Classification
454 /// \~english @par Type
456 /// \~english @par Detail
457 /// - Retrieve the current priority of the process. Check to see if already at max.\n
458 /// If so just return. Otherwise increase by one and set the priority...
459 /// \~english @see None
460 ////////////////////////////////////////////////////////////////////////////////////
461 void IncreasePriorityByOne(void);
463 /////////////////////////////////////////////////////////////////////////////////////
464 /// \ingroup DecreasePriorityByOne
465 /// \~english @par Summary
466 /// - This method will decrease the priority for the process this object represents by one.
467 /// \~english @param None
468 /// \~english @retval None
469 /// \~english @par Preconditions
471 /// \~english @par Change of the internal state
473 /// \~english @par Causes of failures
475 /// \~english @par Classification
477 /// \~english @par Type
479 /// \~english @par Detail
480 /// - Retrieve the current priority of the process. Check to see if already at minimum.
481 /// If so just return. Otherwise decrease by one and set the priority...
482 /// \~english @see None
483 ////////////////////////////////////////////////////////////////////////////////////
484 void DecreasePriorityByOne(void);
486 /////////////////////////////////////////////////////////////////////////////////////
487 /// \ingroup GetPriority
488 /// \~english @par Summary
489 /// - This method will return to the caller the currently configured process priority.
490 /// \~english @param None
491 /// \~english @retval int priority - process priority
492 /// \~english @par Preconditions
493 /// -no preconditions
494 /// \~english @par Change of the internal state
495 /// - If the result of function sched_getparam(m_tProcessId, &cur_sch_params) is less than -1,\n
496 /// then m_iErrorCode will be seted with errno.
497 /// \~english @par Causes of failures
499 /// \~english @par Classification
501 /// \~english @par Type
503 /// \~english @par Detail
504 /// - If the result of function sched_getparam(m_tProcessId, &cur_sch_params)\n
505 /// is less than -1,will be return -1,else return Currently configured process priority.
506 /// \~english @see None
507 ////////////////////////////////////////////////////////////////////////////////////
508 int const GetPriority(void);
510 /////////////////////////////////////////////////////////////////////////////////////
511 /// \ingroup SetProcessName
512 /// \~english @par Summary
513 /// - This method will set this objects process name member variable to the provided string value.
514 /// \~english @param [in] p_strProcessName_i
515 /// - SS_String - Process Name to set the m_strProcessName member variable to
516 /// \~english @retval None
517 /// \~english @par Preconditions
518 /// -no preconditions
519 /// \~english @par Change of the internal state
520 /// - Using p_strProcessName_i to set m_strProcessName
521 /// \~english @par Causes of failures
523 /// \~english @par Classification
525 /// \~english @par Type
527 /// \~english @par Detail
528 /// - This method will set this objects process name member variable to the provided string value.\n
529 /// If the user of this object wishes to register the name with PosixBasedOS001 OS,\n
530 /// the AttachName() method should be called.
531 /// \~english @see None
532 ////////////////////////////////////////////////////////////////////////////////////
533 void SetProcessName(const SS_String& p_strProcessName_i);
535 /////////////////////////////////////////////////////////////////////////////////////
536 /// \ingroup GetProcessName
537 /// \~english @par Summary
538 /// - Get process name
539 /// \~english @param None
540 /// \~english @retval SS_String - Process Name
541 /// \~english @par Preconditions
542 /// -no preconditions
543 /// \~english @par Change of the internal state
545 /// \~english @par Causes of failures
547 /// \~english @par Classification
549 /// \~english @par Type
551 /// \~english @par Detail
552 /// - This method will return to the caller the registered name of this process.\n
553 /// been registered with the OS, a NULL string will be returned. If a name has not
554 /// \~english @see None
555 ////////////////////////////////////////////////////////////////////////////////////
556 SS_String GetProcessName(void) const {
557 return m_strProcessName;
560 /////////////////////////////////////////////////////////////////////////////////////
561 /// \ingroup CreateProcess
562 /// \~english @par Summary
563 /// - This method will create a process with the executable provided and \n
564 /// mode as a calling parameter.The caller can also provide a list of arguments \n
565 /// that will be provided to the executable at startup.
566 /// \~english @param [in] p_strFile_i
567 /// - SS_String - Path and Filename of executable to create process for
568 /// \~english @param [in] p_strlstArgv_i
569 /// - StringList - List of ARGV values for new process
570 /// \~english @param [in] p_eMode_i
571 /// - eProcessLoadMode - Mode to create and load new process
572 /// \~english @param [in] p_strProcessName_i
573 /// - SS_String - This is the name that will be registered to the OS for this process
574 /// \~english @param [in] p_eSchedulingPolicy_i
575 /// - eProcessSchedulingPolicy
576 /// \~english @param [in] p_iPriority_i
577 /// - int - Priority for this process
578 /// \~english @param [in] unix_user_name
579 /// - char* - unix user name
580 /// \~english @param [in] p_lSpawnFlags_i
581 /// - long - Spawning flags. These are PosixBasedOS001 specific....
583 /// eProcessLoadMode enum
585 /// - enum eProcessLoadMode {
586 /// WAIT, //The invoked program is loaded into available memory, is executed,
587 /// //and then the original program resumes execution.
588 /// NOWAIT, // Causes the current program to execute concurrently with the new child process.
592 /// eProcessSchedulingPolicy enum
594 /// - enum eProcessSchedulingPolicy {
595 /// FIFO, // A fixed priority scheduler in which the highest ready process runs until it
596 /// // blocks or is preempted by a higher priority process.
597 /// ROUND_ROBIN, // The same as FIFO, except processes at the same priority level time-slice.
598 /// OTHER // A general time sharing scheduler in which a process decays in priority if it
599 /// // consumes too much processor before blocking. It reverts to its default priority
600 /// // when it blocks. Should it fail to run over a 2 second period and it has decayed
601 /// // then it's boosted one priority level up to a maximum of its default priority.
604 /// \~english @retval None
605 /// \~english @par Preconditions
606 /// -no preconditions
607 /// \~english @par Change of the internal state
608 /// - set m_iErrorCode with 0
609 /// set m_iReturnCode with 0
610 /// set m_eProcessLoadMode with p_eMode_i;
611 /// set m_strFile with p_strFile_i;
612 /// set m_strProcessName with p_strProcessName_i;
613 /// use the result of function CL_ProcessCreate() to set m_tProcessId
614 /// \~english @par Causes of failures
616 /// \~english @par Classification
618 /// \~english @par Type
620 /// \~english @par Detail
621 /// -This method will create a PosixBasedOS001 process with the executable provided\n
622 /// and mode as a calling parameter.The caller can also provide a list of arguments\n
623 /// that will be provided to the executable at startup.The calling p_strProcessName \m
624 /// parameter is a textual name that will be associated with the newly created process\n
625 /// by the OS. The process state information will be maintained by this object.\n
626 /// Upon successful creation of the process, the scheduling policy and priority\n
627 /// of the process will be set to the provided values. The user can change these\n
628 /// values through the SetSchedulingPolicy() and SetPriority() method calls.\n
629 /// Using unix_user_name to get uid and gid,set uid and gid when calling\n
630 /// CL_ProcessCreateAttrSetUid() and CL_ProcessCreateAttrSetGid\n
631 /// \~english @see None
632 ////////////////////////////////////////////////////////////////////////////////////
633 void CreateProcess(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
634 const StringList& p_strlstArgv_i, // List of ARGV values for new process
635 const eProcessLoadMode p_eMode_i, // Mode to create and load new process
636 const SS_String& p_strProcessName_i, // This is the name that will be registered to the OS for this process
637 const eProcessSchedulingPolicy p_eSchedulingPolicy_i, // Scheduling Policy for this process
638 const int p_iPriority_i, // Priority for this process
639 const char* unix_user_name, const long p_lSpawnFlags_i); // Spawning flags. These are PosixBasedOS001 specific.... // NOLINT (runtime/int)
641 /////////////////////////////////////////////////////////////////////////////////////
642 /// \ingroup CreateProcess
643 /// \~english @par Summary
644 /// - This method will create a PosixBasedOS001 process with the executable\n
645 /// provided and mode as a calling parameter.
646 /// \~english @param [in] p_strFile_i
647 /// - SS_String - Path and Filename of executable to create process for
648 /// \~english @param [in] p_strProcessName_i
649 /// - SS_String - This is the name that will be registered to the OS for this process
650 /// \~english @param [in] unix_user_name
651 /// - char* - unix user name
652 /// \~english @param [in] p_lSpawnFlags_i
653 /// - long - Posix Spawning flags. These are PosixBasedOS001 specific
654 /// \~english @retval None
655 /// \~english @par Preconditions
656 /// -no preconditions
657 /// \~english @par Change of the internal state
659 /// \~english @par Causes of failures
661 /// \~english @par Classification
663 /// \~english @par Type
665 /// \~english @par Detail
666 /// - The caller can also provide a list of arguments that will be provided\n
667 /// to the executable at startup.The calling p_strProcessName parameter is a textual name\n
668 /// that will be associated with the newly created process by the OS.\n
669 /// The process state information will be maintained by this object.
670 /// \~english @see None
671 ////////////////////////////////////////////////////////////////////////////////////
672 void CreateProcess(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
673 const SS_String& p_strProcessName_i, // This is the name that will be registered to the OS for this process
674 const char* unix_user_name = NULL, const long p_lSpawnFlags_i = // NOLINT (runtime/int)
675 iProcess_DEFAULT_PROCESS_FLAGS); // Spawning flags.
676 // These are PosixBasedOS001 specific....
677 /////////////////////////////////////////////////////////////////////////////////////
678 /// \ingroup CreateProcess
679 /// \~english @par Summary
680 /// - This method will create a process with the executable
681 /// provided and mode as a calling parameter.
682 /// \~english @param [in] p_strFile_i
683 /// - SS_String - Path and Filename of executable to create
685 /// \~english @param [in] p_strProcessName_i
686 /// - SS_String - This is the name that will be registered to the
687 /// OS for this process
688 /// \~english @param [in] p_iPriority_i
689 /// - int - Priority of process
690 /// \~english @param [in] unix_user_name
691 /// - char* - unix user name
692 /// \~english @param [in] p_lSpawnFlags_i
693 /// - long - Posix Spawning flags. These are PosixBasedOS001
695 /// \~english @retval None
696 /// \~english @par Preconditions
697 /// -no preconditions
698 /// \~english @par Change of the internal state
700 /// \~english @par Causes of failures
702 /// \~english @par Classification
704 /// \~english @par Type
706 /// \~english @par Detail
707 /// - The caller can also provide a list of arguments that will be
709 /// to the executable at startup.The calling p_strProcessName
710 /// parameter is a textual name\n
711 /// that will be associated with the newly created process by
713 /// The process state information will be maintained by this
715 /// \~english @see None
716 ////////////////////////////////////////////////////////////////////////////////////
717 void CreateProcess(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
718 const SS_String& p_strProcessName_i, // This is the name that will be registered to the OS for this process
719 const int p_iPriority_i, // Priority of this process
720 const char* unix_user_name = NULL, const long p_lSpawnFlags_i = // NOLINT (runtime/int)
721 iProcess_DEFAULT_PROCESS_FLAGS); // Spawning flags.
722 // These are PosixBasedOS001 specific....
724 /////////////////////////////////////////////////////////////////////////////////////
725 /// \ingroup CreateProcess
726 /// \~english @par Summary
727 /// - This method will create a process with the executable provided and mode as a calling parameter.
728 /// \~english @param [in] p_strFile_i
729 /// - SS_String - p_strFile_i Path and Filename of executable to create process for
730 /// \~english @param [in] unix_user_name
731 /// - char* - unix user name
732 /// \~english @param [in] p_lSpawnFlags_i
733 /// - long - Spawning flags. These are PosixBasedOS001 specific.
734 /// \~english @retval None
735 /// \~english @par Preconditions
737 /// \~english @par Change of the internal state
739 /// \~english @par Causes of failures
741 /// \~english @par Classification
743 /// \~english @par Type
745 /// \~english @par Detail
746 /// - The caller can also provide a list of arguments that will be provided\n
747 /// to the executable at startup.The calling p_strProcessName parameter is a textual name\n
748 /// that will be associated with the newly created process by the OS.\n
749 /// The process state information will be maintained by this object.
750 /// \~english @see None
751 ////////////////////////////////////////////////////////////////////////////////////
752 void CreateProcess(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
753 const char* unix_user_name = NULL, const long p_lSpawnFlags_i = // NOLINT (runtime/int)
754 iProcess_DEFAULT_PROCESS_FLAGS); // Spawning flags.
755 // These are PosixBasedOS001 specific....
757 /////////////////////////////////////////////////////////////////////////////////////
758 /// \ingroup CreateProcess
759 /// \~english @par Summary
760 /// - This method will create a process with the executable provided and mode as a calling parameter.
761 /// \~english @param [in] p_strFile_i
762 /// - SS_String - p_strFile_i Path and Filename of executable to create process for
763 /// \~english @param [in] p_strProcessName_i
764 /// - SS_String - This is the name that will be registered to the OS for this process
765 /// \~english @param [in] p_strlstArgv_i
766 /// - StringList - List of ARGV values for new process
767 /// \~english @param [in] unix_user_name
768 /// - char* - unix user name
769 /// \~english @param [in] p_lSpawnFlags_i
770 /// - long - Spawning flags. These are PosixBasedOS001 specific.
771 /// \~english @retval None
772 /// \~english @par Preconditions
773 /// -no preconditions
774 /// \~english @par Change of the internal state
776 /// \~english @par Causes of failures
778 /// \~english @par Classification
780 /// \~english @par Type
782 /// \~english @par Detail
783 /// - The caller can also provide a list of arguments that will be provided\n
784 /// to the executable at startup.The calling p_strProcessName parameter is a textual name\n
785 /// that will be associated with the newly created process by the OS.\n
786 /// The process state information will be maintained by this object.
787 /// \~english @see None
788 ////////////////////////////////////////////////////////////////////////////////////
789 void CreateProcess(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
790 const SS_String& p_strProcessName_i, // This is the name that will be registered to the OS for this process
791 const StringList& p_strlstArgv_i, // List of ARGV values for new process
792 const char* unix_user_name = NULL, const long p_lSpawnFlags_i = // NOLINT (runtime/int)
793 iProcess_DEFAULT_PROCESS_FLAGS); // Spawning flags.
794 // These are PosixBasedOS001 specific....
796 /////////////////////////////////////////////////////////////////////////////////////
797 /// \ingroup CreateProcess
798 /// \~english @par Summary
799 /// - This method will create a process with the executable provided and mode as a calling parameter.
800 /// \~english @param [in] p_strFile_i
801 /// - SS_String - Path and Filename of executable to create process for
802 /// \~english @param [in] p_strProcessName_i
803 /// - SS_String - This is the name that will be registered to the OS for this process
804 /// \~english @param [in] p_iPriority_i
805 /// - int - Priority for this process
806 /// \~english @param [in] p_strlstArgv_i
807 /// - StringList - List of ARGV values for new process
808 /// \~english @param [in] unix_user_name
809 /// - char* - unix user name
810 /// \~english @param [in] p_lSpawnFlags_i
811 /// - long - Spawning flags.These are PosixBasedOS001 specific.
812 /// \~english @retval None
813 /// \~english @par Preconditions
814 /// -no preconditions
815 /// \~english @par Change of the internal state
817 /// \~english @par Causes of failures
819 /// \~english @par Classification
821 /// \~english @par Type
823 /// \~english @par Detail
824 /// - The caller can also provide a list of arguments that will be provided\n
825 /// to the executable at startup.The calling p_strProcessName parameter is a textual name\n
826 /// that will be associated with the newly created process by the OS.\n
827 /// The process state information will be maintained by this object.
828 /// \~english @see None
829 ////////////////////////////////////////////////////////////////////////////////////
830 void CreateProcess(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
831 const SS_String& p_strProcessName_i, // This is the name that will be registered to the OS for this process
832 const int p_iPriority_i, // Priority for this process
833 const StringList& p_strlstArgv_i, // List of ARGV values for new process
834 const char* unix_user_name = NULL, const long p_lSpawnFlags_i = // NOLINT (runtime/int)
835 iProcess_DEFAULT_PROCESS_FLAGS); // Spawning flags.
836 // These are PosixBasedOS001 specific....
837 /////////////////////////////////////////////////////////////////////////////////////
838 /// \ingroup CreateProcess
839 /// \~english @par Summary
840 /// - This method will create a process with the executable provided and mode as a calling parameter.
841 /// \~english @param [in] p_strFile_i
842 /// - SS_String - Path and Filename of executable to create process for
843 /// \~english @param [in] c_argv
844 /// - char - This is the argument that will be registered to the OS for this process
845 /// \~english @param [in] environment_string
846 /// - char - enviroment for this process
847 /// \~english @param [in] cl_attr
848 /// - CL_ProcessAttr_t - List of ARGV values for new process
849 /// \~english @retval None
850 /// \~english @par Preconditions
851 /// -no preconditions
852 /// \~english @par Change of the internal state
854 /// \~english @par Causes of failures
856 /// \~english @par Classification
858 /// \~english @par Type
860 /// \~english @par Detail
861 /// - The caller can also provide a list of arguments that will be provided\n
862 /// that will be associated with the newly created process by the OS.\n
863 /// The process state information will be maintained by this object.
864 /// \~english @see None
865 ////////////////////////////////////////////////////////////////////////////////////
866 void CreateProcess(const SS_String* p_str_file, char* const * c_argv,
867 char* environment_string, const CL_ProcessAttr_t *cl_attr);
869 /////////////////////////////////////////////////////////////////////////////////////
870 /// \ingroup CreateProcessWait
871 /// \~english @par Summary
872 /// - This method will create a process with the executable provided.
873 /// \~english @param [in] p_strFile_i
874 /// - SS_String - Path and Filename of executable to create process for
875 /// \~english @retval None
876 /// \~english @par Preconditions
877 /// -no preconditions
878 /// \~english @par Change of the internal state
880 /// \~english @par Causes of failures
882 /// \~english @par Classification
884 /// \~english @par Type
886 /// \~english @par Detail
887 /// - This method will create a process with the executable provided.\n
888 /// The process state information will be maintained by this object.
889 /// \~english @see None
890 ////////////////////////////////////////////////////////////////////////////////////
891 void CreateProcessWait(const SS_String& p_strFile_i); // Path and Filename of executable to create process for
893 /////////////////////////////////////////////////////////////////////////////////////
894 /// \ingroup CreateProcessWait
895 /// \~english @par Summary
896 /// - This method will create a PosixBasedOS001 process with the executable provided.
897 /// \~english @param [in] p_strFile_i
898 /// - SS_String - Path and Filename of executable to create process for
899 /// \~english @param [in] p_strlstArguments_i
900 /// - StringList - List of process calling arguments
901 /// \~english @retval None
902 /// \~english @par Preconditions
903 /// -no preconditions
904 /// \~english @par Change of the internal state
906 /// \~english @par Causes of failures
908 /// \~english @par Classification
910 /// \~english @par Type
912 /// \~english @par Detail
913 /// - This method will create a PosixBasedOS001 process with the executable provided.\n
914 /// The process state information will be maintained by this object.
915 /// \~english @see None
916 ////////////////////////////////////////////////////////////////////////////////////
917 void CreateProcessWait(const SS_String& p_strFile_i, // Path and Filename of executable to create process for
918 const StringList& p_strlstArguments_i); // List of process calling arguments
920 /////////////////////////////////////////////////////////////////////////////////////
921 /// \ingroup KillProcess
922 /// \~english @par Summary
923 /// - This method will send the specified signal to the process represented by this object
924 /// \~english @param [in] signal
926 /// \~english @retval None
927 /// \~english @par Preconditions
928 /// -no preconditions
929 /// \~english @par Change of the internal state
930 /// - Intialize the objects m_iErrorCode member variable to 0
931 /// \~english @par Causes of failures
933 /// \~english @par Classification
935 /// \~english @par Type
937 /// \~english @par Detail
938 /// - This method will send the specified signal to the process represented by this object.\n
939 /// All variables associated with this object will be initialized to a know value.\n
940 /// If this process has a name registered with the OS, that name will be removed.
941 /// \~english @see None
942 ////////////////////////////////////////////////////////////////////////////////////
943 void KillProcess(int signal = SIGKILL);
945 /////////////////////////////////////////////////////////////////////////////////////
946 /// \ingroup DoesProcessExist
947 /// \~english @par Summary
948 /// -Check if the process existed
949 /// \~english @param None
950 /// \~english @retval TRUE - Process Exists
951 /// \~english @retval FALSE - Process does not exist
952 /// \~english @par Preconditions
953 /// -no preconditions
954 /// \~english @par Change of the internal state
955 /// - The internal state is not changed.
956 /// \~english @par Causes of failures
958 /// \~english @par Classification
960 /// \~english @par Type
962 /// \~english @par Detail
963 /// - This method will return a BOOLean indicating whether this process exists.
965 ////////////////////////////////////////////////////////////////////////////////////
966 BOOL DoesProcessExist(void);
968 /////////////////////////////////////////////////////////////////////////////////////
969 /// \ingroup DisableAutoKill
970 /// \~english @par Summary
972 /// \~english @param None
973 /// \~english @retval None
974 /// \~english @par Preconditions
975 /// -no preconditions
976 /// \~english @par Change of the internal state
977 /// - set m_fAutoKill as FALSE
978 /// \~english @par Causes of failures
980 /// \~english @par Classification
982 /// \~english @par Type
984 /// \~english @par Detail
985 /// - This method will disable the Auto Kill function in the destructor,\n
986 /// thus letting the process whom this object represents continue running.
987 /// \~english @see None
988 ////////////////////////////////////////////////////////////////////////////////////
989 void DisableAutoKill(void) {
993 /////////////////////////////////////////////////////////////////////////////////////
994 /// \ingroup EnableAutoKill
995 /// \~english @par Summary
996 /// - Enable the Auto Kill
997 /// \~english @param None
998 /// \~english @retval None
999 /// \~english @par Preconditions
1000 /// -no preconditions
1001 /// \~english @par Change of the internal state
1002 /// - set m_fAutoKill as TRUE
1003 /// \~english @par Causes of failures
1005 /// \~english @par Classification
1007 /// \~english @par Type
1009 /// \~english @par Detail
1010 /// - This method will Enable the Auto Kill function in the destructor,\n
1011 /// thus killing the process whom this object represents.
1012 /// \~english @see None
1013 ////////////////////////////////////////////////////////////////////////////////////
1014 void EnableAutoKill(void) {
1019 // Class Data Members
1020 //---------------------------------------------
1022 long m_lValidationTag; // Used to check if this is a valid // NOLINT (runtime/int)
1026 pid_t m_tProcessId; // This is the process ID for this process. All command, control,
1027 // and status gathering will use this ID.
1028 eProcessLoadMode m_eProcessLoadMode; // This is the process load mode provided by the caller when this
1029 // process was created.
1030 SS_String m_strFile; // This is the executable path and file name of this process
1031 StringList m_strlstArgv; // This is the calling parameter Argv list provided by the caller.
1032 SS_String m_strProcessName; // This is the name that was registered to the OS for process identification
1034 int m_iErrorCode; // This was the returned PosixBasedOS001 error code for the last call. The programmer
1035 // can look at this error code if an error was detected and an
1036 // exception was thrown.
1037 BOOL m_fAutoKill; // Used to indicate to destructor to kill the process whom this object
1038 // represents on exit.
1041 //////////////////////////////////////////////////////////////////////
1044 /// Copies data members from the specified object to this object.
1045 /// No attempt is made to free dynamically allocated objects within
1046 /// this object (you must do that before calling this function).
1048 ///////////////////////////////////////////////////////////////////////
1049 void Copy(const Process& p_rhs_i);
1051 ////////////////////////////////////////////////////////////////////////////////////////////////////
1052 /// ConvertToPosixBasedOS001SchedularPolicy
1053 /// This method will return to the caller the equivalent PosixBasedOS001 schedular policy for the process
1054 /// that this object represents
1057 /// Calling Arguments:
1058 /// Scheduling Policy
1061 /// FIFO, A fixed priority scheduler in which the highest ready process runs until it
1062 /// blocks or is preempted by a higher priority process.
1063 /// ROUND_ROBIN, The same as FIFO, except processes at the same priority level time-slice.
1064 /// OTHER A general time sharing scheduler in which a process decays in priority if it
1065 /// consumes too much processor before blocking. It reverts to its default priority
1066 /// when it blocks. Should it fail to run over a 2 second period and it has decayed
1067 /// then it's boosted one priority level up to a maximum of its default priority.
1068 //////////////////////////////////////////////////////////////////////////////////////////////////////////
1069 int const ConvertToPosixBasedOS001SchedularPolicy(
1070 const eProcessSchedulingPolicy p_eSchedulingPolicy_i);
1072 ////////////////////////////////////////////////////////////////////////////////////////////////////
1073 /// ConvertFromPosixBasedOS001SchedularPolicy
1075 /// This method will return to the caller the eProcessSchedulingPolicy based on the PosixBasedOS001 schedular
1076 /// policy for the process that this object represents
1079 /// Calling Arguments:
1080 /// PosixBasedOS001 Scheduling Policy
1083 /// FIFO, A fixed priority scheduler in which the highest ready process runs until it
1084 /// blocks or is preempted by a higher priority process.
1085 /// ROUND_ROBIN, The same as FIFO, except processes at the same priority level time-slice.
1086 /// OTHER A general time sharing scheduler in which a process decays in priority if it
1087 /// consumes too much processor before blocking. It reverts to its default priority
1088 /// when it blocks. Should it fail to run over a 2 second period and it has decayed
1089 /// then it's boosted one priority level up to a maximum of its default priority.
1090 ///////////////////////////////////////////////////////////////////////////////////////////////////////
1091 eProcessSchedulingPolicy const ConvertFromPosixBasedOS001SchedularPolicy(
1092 const int p_iPosixBasedOS001chedulingPolicy_i);
1094 ////////////////////////////////////////////////////////////////////////////////////////////////////
1095 /// \ingroup SS_SystemServicesIf
1096 ////////////////////////////////////////////////////////////////////////////////////////////////////
1097 /// \brief Check environment variable MOCK_LIBRARY where Mock Library Name to set in LD_PRELOAD is set
1098 /// and output character string to set in LD_PRELOAD if there is setting.
1100 ////////////////////////////////////////////////////////////////////////////////////////////////////
1101 void CheckLdPreLoad(SS_String *process_path, char *environment_string);
1103 ////////////////////////////////////////////////////////////////////////////////////////////////////
1104 /// \ingroup SS_SystemServicesIf
1105 ////////////////////////////////////////////////////////////////////////////////////////////////////
1106 /// \brief Acquire the character string of the environment variable and set it in String Vector
1107 /// and return in a pointer of Vector.
1108 /// \return vector<SS_String> pointer
1109 ////////////////////////////////////////////////////////////////////////////////////////////////////
1110 std::vector<SS_String> *GetEnvironVector(void);
1111 // ----------------------------------------
1112 // ---------------- End -------------------
1114 #endif // NOLINT (build/header_guard)