common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / nsframework / common_library / client / include / native_service / cl_process.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef _cl_process_h_  // NOLINT(build/header_guard)
18 #define _cl_process_h_  // NOLINT(build/header_guard)
19
20 #include <sys/types.h>
21
22 #define CL_PROCESSS_ATTR_HOLD_FDS_NUM 8
23
24 #define CL_INTFY_FILENAME_FORMAT "/tmp/intfy_%05d"
25
26 /////////////////////////////////////////////////////////////////////////////////////
27 /// \ingroup CL_ProcessAttr_t
28 /// \~english @par Brief
29 ///        Process attribute structure
30 /////////////////////////////////////////////////////////////////////////////////////
31 typedef struct {
32   char body[148];  ///< process attribute
33 } CL_ProcessAttr_t;
34
35 /////////////////////////////////////////////////////////////////////////////////////
36 /// \ingroup CL_ProcessCleanupInfo_t
37 /// \~english @par Brief
38 ///        Child-process attribute structure
39 /////////////////////////////////////////////////////////////////////////////////////
40 typedef struct {
41   pid_t pid;       ///< child-process ID
42   int code;        ///< signal code
43   int status;      ///< end status or signal
44 } CL_ProcessCleanupInfo_t;
45
46 /////////////////////////////////////////////////////////////////////////////////////
47 /// \ingroup CL_ProcessSchedPolicy_t
48 /// \~english @par Brief
49 ///        Schedule policy
50 /////////////////////////////////////////////////////////////////////////////////////
51 typedef enum {
52   CL_PROCESS_SCHED_POLICY_OTHER = 0,  ///< TSS
53   CL_PROCESS_SCHED_POLICY_RR,         ///< Round robin
54   CL_PROCESS_SCHED_POLICY_FIFO,       ///< FIFO
55 } CL_ProcessSchedPolicy_t;
56
57 typedef struct {
58   char body[20];
59 } CL_ThreadAttr_t;
60
61 /////////////////////////////////////////////////////////////////////////////////////
62 /// \ingroup CL_ProcessCreateCgroupAttr_t
63 /// Cgroup attribute structure
64 /////////////////////////////////////////////////////////////////////////////////////
65 typedef struct {
66   char body[24];  ///< Cgroup attribute
67 } CL_ProcessCreateCgroupAttr_t;
68
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 /**
73  * @file cl_process.h
74  * @brief \~english This file contains the base api,enum and struct of cl_process.
75  */
76
77 /** @addtogroup BaseSystem
78  *  @{
79  */
80 /** @addtogroup native_service
81  *  @ingroup BaseSystem
82  *  @{
83  */
84 /** @addtogroup common_library
85  *  @ingroup native_service
86  *  @{
87  */
88
89 /////////////////////////////////////////////////////////////////////////////////////
90 /// \ingroup CL_ProcessInit
91 /// \~english @par Brief
92 ///        Initialize the process
93 /// \~english @retval int file  descriptor
94 /// \~english @retval -1 Error
95 /// \~english @par Prerequisite
96 ///        - Prerequisites are nothing.
97 /// \~english @par Change of internal state
98 ///        - Change of internal state according to the API does not occur.
99 /// \~english @par Conditions of processing failure
100 ///        - Failed to set up process prctl, -1 is returned.
101 ///        - Failed to set the signal set to the empty set sigemptyset, -1 is returned.
102 ///        - Failed to add a signal to the signal mask sigaddset, -1 is returned.
103 ///        - Failed to set sigprocmask, -1 is returned.
104 ///        - Failed to create a scripter in the file for signal acceptance signalfd, -1 is returned.
105 /// \~english @par Detail
106 ///        This API must be called before createing a thread.
107 ///        Therefore, it is recommended that this API be called from within the main() function immediately after the API started.\n
108 ///        Initialize the process.\n
109 ///        The retuen value fd is assumed to be poll/select and used for waiting for event.\n
110 ///        An ready occurs when the child process terminates.\n
111 ///        Call process name setting(\ref CL_ProcessCreateAttrSetName) uniformly
112 ///        because it is applied only to the number of architecture after exec.\n
113 /// \~english @par Classification
114 ///        Public
115 /// \~english @par Type
116 ///        No match
117 /// \~english @see
118 ///        none
119 ////////////////////////////////////////////////////////////////////////////////////
120 int CL_ProcessInit(void);  // NOLINT(readability/nolint)
121
122 /////////////////////////////////////////////////////////////////////////////////////
123 /// \ingroup CL_ProcessCreate
124 /// \~english @par Brief
125 ///        Create the process
126 /// \~english @param [in] file
127 ///        const char*   -
128 /// \~english @param [in] argv[]
129 ///        char* const  -
130 /// \~english @param [in] envp[]
131 ///        char* const
132 /// \~english @param [in] attr
133 ///        const CL_ProcessAttr_t* - Process attribute pointer
134 /// \~english @par
135 ///        CL_ProcessAttr_t struct
136 /// \~english @code
137 ///                 typedef struct {
138 ///                   char body[148];
139 ///                 } CL_ProcessAttr_t;
140 ///            @endcode
141 /// \~english @retval int Success(PID)
142 /// \~english @retval -1 Error
143 /// \~english @par Prerequisite
144 ///        - Need to be running CL_ProcessInit.
145 ///        - Initialize attr with CL_ProcessCreateAttrInit.
146 /// \~english @par Change of internal state
147 ///        - Change of internal state according to the API does not occur.
148 /// \~english @par Conditions of processing failure
149 ///        - When the executable name (file) in the argument is NULL, set errno to EINVAL, -1 is returned.
150 ///        - When the ARG parameter (argv[]) in the argument is NULL, set errno to EINVAL, -1 is returned.
151 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
152 ///          set errno to EINVAL, -1 is returned.
153 ///        - When memory (malloc) of the data storagee area of the environment variable parameter (envp[]) specified
154 ///          by the arguments fails, set errno to EINVAL, -1 is returned.
155 ///        - When memory (malloc) of the data control area of the environment variable parameter (envp[]) specified
156 ///          by the arguments fails, set errno to EINVAL, -1 is returned.
157 ///        - Process creation (fork) fail, -1 is returned.
158 ///        - Process CPU affinity masking (sched_setaffinity) fail, -1 is returned.
159 ///        - When the character string output processing (snprintf) for process creation fail, -1 is returned.
160 ///        - When the character string output processing (snprintf) for PID setting of cgroup fail, -1 is returned.
161 ///        - Failure to allocate the area fo sstoring the path name of cgroup (malloc), -1 is returned.
162 ///        - Failure to open file descriptor (open) of cgroup, -1 is returned.
163 ///        - Failure to write file descriptor (write) of cgroup, -1 is returned.
164 /// \~english @par Detail
165 ///        - This API must be called before createing a thread.
166 /// \~english @par
167 ///        Create the process.\n
168 ///        The ARG parameter (argv[]) specified in the argment must satisfy the following conditions:\n
169 ///        - Can not be omitted.\n
170 ///        - The first argument must specify a pointer o the filename to be executed.\n
171 ///        - An array of pointer to NULL terminated strings.\n
172 ///        - Arrays must be terminated by NULL pointer.\n
173 /// \~english @par
174 ///        Enviroment-variable parameters (envp[]) specified in arguments mus satisfy the following condiions:\n
175 ///        - When NULL is specified, the parent process inherits the parent process's environment variables.\n
176 ///        - An array of pointer to NULL terminated strings.\n
177 ///        - Arrays must be terminated by NULL pointer.\n
178 /// \~english @par
179 ///        Be aware of the following.\n
180 ///        - Processing continues without interrupting event if setrlimit() fail.\n
181 ///        - System call access() checks whether or not there is access privilege,
182 ///          but returns PID regardless of the access privilege status.
183 ///          (If the process does not have access privilege, 100 retries are executed at 100 microseconds.)
184 /// \~english @par
185 ///        Since the process attribute of a process cannot be changed during processing,
186 ///        if it is necessary to change the process attribute,
187 ///        it is necessary to call the following API and change the process attribute before calling this API.\n
188 ///          - CL_ProcessCreateAttrInit Initialize process attribute
189 ///          - CL_ProcessCreateAttrSetCgroup Setting process attribute (Cgroup)
190 ///          - CL_ProcessCreateAttrSetDisableCloseFds Setting process attribute (stop compulsion FD close)
191 ///          - CL_ProcessCreateAttrSetGid Setting process attribute (group ID)
192 ///          - CL_ProcessCreateAttrSetGroup Setting process attribute (process group)
193 ///          - CL_ProcessCreateAttrSetHoldFds Setting process attribute (maintain FD)
194 ///          - CL_ProcessCreateAttrSetName Setting process attribute (process name)
195 ///          - CL_ProcessCreateAttrSetSchedule Setting process attribute (schedule policy and priority)
196 ///          - CL_ProcessCreateAttrSetStackSize Setting process attribute (Stack Size)
197 ///          - CL_ProcessCreateAttrSetUid Setting process attribute (user ID)
198 /// \~english @par Classification
199 ///        Public
200 /// \~english @par Type
201 ///        Open Close
202 /// \~english @see
203 ///        CL_ProcessTerminate, CL_ProcessTerminateGroup
204 ///        CL_ProcessCreateAttrInit, CL_ProcessCreateAttrSetCgroup,
205 ///        CL_ProcessCreateAttrSetDisableCloseFds, CL_ProcessCreateAttrSetGid,
206 ///        CL_ProcessCreateAttrSetGroup, CL_ProcessCreateAttrSetHoldFds,
207 ///        CL_ProcessCreateAttrSetName, CL_ProcessCreateAttrSetSchedule,
208 ///        CL_ProcessCreateAttrSetStackSize, CL_ProcessCreateAttrSetUid
209 ////////////////////////////////////////////////////////////////////////////////////
210 int CL_ProcessCreate(const char *file, char * const argv[], char * const envp[],  // NOLINT(readability/nolint)
211                      const CL_ProcessAttr_t *attr);
212
213 ////////////////////////////////////////////////////////////////////////////////////
214 /// \ingroup CL_ProcessCreateAttrInit
215 /// \~english @par Brief
216 ///        Initialize process attribute
217 /// \~english @param [out] attr
218 ///        const CL_ProcessAttr_t* - Process attribute pointer
219 /// \~english @par
220 ///        CL_ProcessAttr_t struct
221 /// \~english @code
222 ///                 typedef struct {
223 ///                   char body[148];
224 ///                 } CL_ProcessAttr_t;
225 ///            @endcode
226 /// \~english @retval 0 Success
227 /// \~english @retval -1 Error
228 /// \~english @par Prerequisite
229 ///        - Prerequisites are nothing.
230 /// \~english @par Change of internal state
231 ///        - Change of internal state according to the API does not occur.
232 /// \~english @par Conditions of processing failure
233 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
234 ///          set errno to EINVAL, -1 is returned.
235 /// \~english @par Detail
236 ///        Initilize the CL_ProcessAttr_t structure that stores process attribute.\n
237 /// \~english @par Classification
238 ///        Public
239 /// \~english @par Type
240 ///        Method(Async) / Fire and Forget / Broadcast / Sync / Set Get / Open Close / Request Notify / No match
241 /// \~english @see
242 ///        none
243 ////////////////////////////////////////////////////////////////////////////////////
244 int CL_ProcessCreateAttrInit(CL_ProcessAttr_t *attr);  // NOLINT(readability/nolint)
245
246 ////////////////////////////////////////////////////////////////////////////////////
247 /// \ingroup CL_ProcessCreateAttrSetName
248 /// \~english @par Brief
249 ///        Set process name in process attribute
250 /// \~english @param [in,out] attr
251 ///        const CL_ProcessAttr_t* - Process attribute pointer
252 /// \~english @param [in] name
253 ///        const char*   - process name (max length 16byte)
254 /// \~english @par
255 ///        CL_ProcessAttr_t struct
256 /// \~english @code
257 ///                 typedef struct {
258 ///                   char body[148];
259 ///                 } CL_ProcessAttr_t;
260 ///            @endcode
261 /// \~english @retval 0 Success
262 /// \~english @retval -1 Error
263 /// \~english @par Prerequisite
264 ///        - Initialize attr with CL_ProcessCreateAttrInit.
265 /// \~english @par Change of internal state
266 ///        - Change of internal state according to the API does not occur.
267 /// \~english @par Conditions of processing failure
268 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
269 ///          set errno to EINVAL, -1 is returned.
270 ///        - When the pointer (name) to the character string hat stores the process name specified
271 ///          by the argument is NULL, set errno to EINVAL, -1 is returned.
272 /// \~english @par Detail
273 ///        Set process name to process attribute.\n
274 ///        The charactr string that stores the process name specified by the argument must satisfy the following conditions:\n
275 ///        - Terminated by a NULL.\n
276 ///        - The maximum lengthof character string is 16 byte including the termination character.\n
277 /// \~english @par Classification
278 ///        Public
279 /// \~english @par Type
280 ///        No match
281 /// \~english @see
282 ///        none
283 ////////////////////////////////////////////////////////////////////////////////////
284 int CL_ProcessCreateAttrSetName(CL_ProcessAttr_t *attr, const char *name);  // NOLINT(readability/nolint)
285
286 ////////////////////////////////////////////////////////////////////////////////////
287 /// \ingroup CL_ProcessCreateAttrSetUid
288 /// \~english @par Brief
289 ///        Set process attribute to user ID
290 /// \~english @param [in,out] attr
291 ///        const CL_ProcessAttr_t* - Process attribute pointer
292 /// \~english @param [in] uid
293 ///        uid_t   - user ID
294 /// \~english @par
295 ///        CL_ProcessAttr_t struct
296 /// \~english @code
297 ///                 typedef struct {
298 ///                   char body[148];
299 ///                 } CL_ProcessAttr_t;
300 ///            @endcode
301 /// \~english @retval 0 Success
302 /// \~english @retval -1 Error
303 /// \~english @par Prerequisite
304 ///        - Initialize attr with CL_ProcessCreateAttrInit.
305 /// \~english @par Change of internal state
306 ///        - Change of internal state according to the API does not occur.
307 /// \~english @par Conditions of processing failure
308 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
309 ///          set errno to EINVAL, -1 is returned.
310 /// \~english @par Detail
311 ///        Set process attribute to user ID.\n
312 ///        When UINT_MAX is set for the user ID,
313 ///        the user ID is set to 0 in the process attribute in the processing of CL_ProcessCreate().\n
314 ///        When 0 is set for the user ID,
315 ///        it is not reflected in the process attribute becose if is played by the process of CL_ProcessCreate().\n
316 /// \~english @par Classification
317 ///        Public
318 /// \~english @par Type
319 ///        No match
320 /// \~english @see
321 ///        none
322 ////////////////////////////////////////////////////////////////////////////////////
323 int CL_ProcessCreateAttrSetUid(CL_ProcessAttr_t *attr, uid_t uid);  // NOLINT(readability/nolint)
324
325 ////////////////////////////////////////////////////////////////////////////////////
326 /// \ingroup CL_ProcessCreateAttrSetGid
327 /// \~english @par Brief
328 ///        Set process attribute to group ID
329 /// \~english @param [in,out] attr
330 ///        const CL_ProcessAttr_t* - Process attribute pointer
331 /// \~english @param [in] gid
332 ///        gid_t   - Group ID
333 /// \~english @par
334 ///        CL_ProcessAttr_t struct
335 /// \~english @code
336 ///                 typedef struct {
337 ///                   char body[148];
338 ///                 } CL_ProcessAttr_t;
339 ///            @endcode
340 /// \~english @retval 0 Success
341 /// \~english @retval -1 Error
342 /// \~english @par Prerequisite
343 ///        - Initialize attr with CL_ProcessCreateAttrInit.
344 /// \~english @par Change of internal state
345 ///        - Change of internal state according to the API does not occur.
346 /// \~english @par Conditions of processing failure
347 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
348 ///          set errno to EINVAL, -1 is returned.
349 /// \~english @par Detail
350 ///        Set process attribute to group ID.\n
351 ///        When 0 is set for the group ID,
352 ///        it is not reflected in the process attribute becose if is played by the process of CL_ProcessCreate().\n
353 /// \~english @par Classification
354 ///        Public
355 /// \~english @par Type
356 ///        No match
357 /// \~english @see
358 ///        none
359 ////////////////////////////////////////////////////////////////////////////////////
360 int CL_ProcessCreateAttrSetGid(CL_ProcessAttr_t *attr, gid_t gid);  // NOLINT(readability/nolint)
361
362 ////////////////////////////////////////////////////////////////////////////////////
363 /// \ingroup CL_ProcessCreateAttrSetSchedule
364 /// \~english @par Brief
365 ///        Set process attribute to schedule policy and priority
366 /// \~english @param [in,out] attr
367 ///        const CL_ProcessAttr_t* - Process attribute pointer
368 /// \~english @param [in] policy
369 ///        CL_ProcessSchedPolicy_t   - schedule policy
370 /// \~english @param [in] priority
371 ///        int   - priority
372 /// \~english @par
373 ///        CL_ProcessAttr_t struct
374 /// \~english @code
375 ///                 typedef struct {
376 ///                   char body[148];
377 ///                 } CL_ProcessAttr_t;
378 ///            @endcode
379 /// \~english @par
380 ///        enum CL_ProcessSchedPolicy_t Variable
381 /// \~english @code
382 ///                 typedef enum {
383 ///                   CL_PROCESS_SCHED_POLICY_OTHER = 0,  // TSS
384 ///                   CL_PROCESS_SCHED_POLICY_RR,         // Round-robin
385 ///                   CL_PROCESS_SCHED_POLICY_FIFO,       // FIFO
386 ///                 } CL_ProcessSchedPolicy_t;
387 ///            @endcode
388 /// \~english @par
389 ///        target to priority
390 ///        - -20~19 : CL_PROCESS_SCHED_POLICY_OTHER
391 ///        -   1~99 : CL_PROCESS_SCHED_POLICY_RR or CL_PROCESS_SCHED_POLICY_FIFO
392 /// \~english @retval 0 Success
393 /// \~english @retval -1 Error
394 /// \~english @par Prerequisite
395 ///        - Initialize attr with CL_ProcessCreateAttrInit.
396 /// \~english @par Change of internal state
397 ///        - Change of internal state according to the API does not occur.
398 /// \~english @par Conditions of processing failure
399 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
400 ///          set errno to EINVAL, -1 is returned.
401 ///        - When the schedule policy (policy) specified in the parameter is CL_PROCESS_SCHED_POLICY_RR
402 ///          and the priority (priority) is other than 1 to 99, set errno to EINVAL, -1 is returned.
403 ///        - When the schedule policy (policy) specified in the parameter is CL_PROCESS_SCHED_POLICY_FIFO
404 ///          and the priority (priority) is other than 1 to 99, set errno to EINVAL, -1 is returned.
405 ///        - Incorrect parameters are specified for the schedule policy (policy) specified in the arguments,
406 ///          set errno to EINVAL, -1 is returned.
407 /// \~english @par Detail
408 ///        Set process attribute to schedule policy and priority.\n
409 ///        Error occur if the real-time schedule policy is set and
410 ///        the priority is passed value outside the range of 1-99.\n
411 ///        In the case of TSS, an error does not occur even if it is outside the range of -20 to 19,
412 ///        but ti is rounded to the nearest integer by a system call when a process is created.\n
413 ///        If not set by this funtion, the schedule policy set the TSS and priority sets 0.\n
414 /// \~english @par Classification
415 ///        Public
416 /// \~english @par Type
417 ///        No match
418 /// \~english @see
419 ///        none
420 ////////////////////////////////////////////////////////////////////////////////////
421 int CL_ProcessCreateAttrSetSchedule(CL_ProcessAttr_t *attr,  // NOLINT(readability/nolint)
422                                     CL_ProcessSchedPolicy_t policy,
423                                     int priority);
424
425 ////////////////////////////////////////////////////////////////////////////////////
426 /// \ingroup CL_ProcessCreateAttrSetGroup
427 /// \~english @par Brief
428 ///        Set process attribute to process group
429 /// \~english @param [in,out] attr
430 ///        const CL_ProcessAttr_t* - Process attribute pointer
431 /// \~english @param [in] create
432 ///        int   - (0 or 1)
433 /// \~english @par
434 ///        - 1  make
435 ///        - 0  not make(default)
436 /// \~english @par
437 ///        CL_ProcessAttr_t struct
438 /// \~english @code
439 ///                 typedef struct {
440 ///                   char body[148];
441 ///                 } CL_ProcessAttr_t;
442 ///            @endcode
443 /// \~english @retval 0 Success
444 /// \~english @retval -1 Error
445 /// \~english @par Prerequisite
446 ///        - Initialize attr with CL_ProcessCreateAttrInit.
447 /// \~english @par Change of internal state
448 ///        - Change of internal state according to the API does not occur.
449 /// \~english @par Conditions of processing failure
450 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
451 ///          set errno to EINVAL, -1 is returned.
452 ///        - When a value oher than 0 or 1 is secified for the process group cration flag (create)
453 ///          specified in the parameter, set errno to EINVAL, -1 is returned.
454 /// \~english @par Detail
455 ///        Set process attribute to process group.\n
456 ///        When a process group is created, all descendant process fork from child process also belong
457 ///        to the same process group, and the entire process group can be forcibly terminated.\n
458 /// \~english @par Classification
459 ///        Public
460 /// \~english @par Type
461 ///        No match
462 /// \~english @see
463 ///        none
464 ////////////////////////////////////////////////////////////////////////////////////
465 int CL_ProcessCreateAttrSetGroup(CL_ProcessAttr_t *attr, int create);  // NOLINT(readability/nolint)
466
467 int CL_ProcessCreateAttrSetCpuAssign(CL_ProcessAttr_t *attr, int cpu_assign);  // NOLINT(readability/nolint)
468
469 ////////////////////////////////////////////////////////////////////////////////////
470 /// \ingroup CL_ProcessCreateAttrSetStackSize
471 /// \~english @par Brief
472 ///        Set process attribute to stack size
473 /// \~english @param [in,out] attr
474 ///        const CL_ProcessAttr_t* - Process attribute pointer
475 /// \~english @param [in] stack_size
476 ///        int   - stack size(byte)
477 /// \~english @par
478 ///        CL_ProcessAttr_t struct
479 /// \~english @code
480 ///                 typedef struct {
481 ///                   char body[148];
482 ///                 } CL_ProcessAttr_t;
483 ///            @endcode
484 /// \~english @retval 0 Success
485 /// \~english @retval -1 Error
486 /// \~english @par Prerequisite
487 ///        - Initialize attr with CL_ProcessCreateAttrInit.
488 /// \~english @par Change of internal state
489 ///        - Change of internal state according to the API does not occur.
490 /// \~english @par Conditions of processing failure
491 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
492 ///          set errno to EINVAL, -1 is returned.
493 /// \~english @par Detail
494 ///        Set process attribute to stack size.\n
495 ///        The muximum configurable stack size is 1MB.\n
496 /// \~english @par Classification
497 ///        Public
498 /// \~english @par Type
499 ///        No match
500 /// \~english @see
501 ///        none
502 ////////////////////////////////////////////////////////////////////////////////////
503 int CL_ProcessCreateAttrSetStackSize(CL_ProcessAttr_t *attr, int stack_size);  // NOLINT(readability/nolint)
504
505 ////////////////////////////////////////////////////////////////////////////////////
506 /// \ingroup CL_ProcessCreateAttrSetHoldFds
507 /// \~english @par Brief
508 ///        Set process attribute to FD to maintain
509 /// \~english @param [in,out] attr
510 ///        const CL_ProcessAttr_t* - Process attribute pointer
511 /// \~english @param [in] hold_fds[]
512 ///        int   -
513 /// \~english @par
514 ///        CL_ProcessAttr_t struct
515 /// \~english @code
516 ///                 typedef struct {
517 ///                   char body[148];
518 ///                 } CL_ProcessAttr_t;
519 ///            @endcode
520 /// \~english @retval 0 Success
521 /// \~english @retval -1 Error
522 /// \~english @par Prerequisite
523 ///        - Initialize attr with CL_ProcessCreateAttrInit.
524 /// \~english @par Change of internal state
525 ///        - Change of internal state according to the API does not occur.
526 /// \~english @par Conditions of processing failure
527 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
528 ///          set errno to EINVAL, -1 is returned.
529 ///        - When the array (hode_openfd[]) storing the list of the FD to be maintained specified
530 ///          by the arguments is NULL, set errno to EINVAL, -1 is returned.
531 /// \~english @par Detail
532 ///        Set process attribute to FD to maintain.\n
533 ///        When nothing is set, FD other than 0, 1, and 2 are automatically close.\n
534 ///        For hold_openfds is stored in a CL_PROCESSS_ATTR_HOLD_FDS_NUM array,
535 ///        it is recommended that int hold_openfds[CL_PROCESSS_ATTR_HOLD_FDS_NUM] be used.\n
536 /// \~english @par Classification
537 ///        Public
538 /// \~english @par Type
539 ///        No match
540 /// \~english @see
541 ///        none
542 ////////////////////////////////////////////////////////////////////////////////////
543 int CL_ProcessCreateAttrSetHoldFds(CL_ProcessAttr_t *attr, int hold_fds[]);  // NOLINT(readability/nolint)
544
545 ////////////////////////////////////////////////////////////////////////////////////
546 /// \ingroup CL_ProcessCreateAttrSetDisableCloseFds
547 /// \~english @par Brief
548 ///        Set process attribute to suspend forced FD close
549 /// \~english @param [in,out] attr
550 ///        const CL_ProcessAttr_t* - Process attribute pointer
551 /// \~english @par
552 ///        CL_ProcessAttr_t struct
553 /// \~english @code
554 ///                 typedef struct {
555 ///                   char body[148];
556 ///                 } CL_ProcessAttr_t;
557 ///            @endcode
558 /// \~english @retval 0 Success
559 /// \~english @retval -1 Error
560 /// \~english @par Prerequisite
561 ///        - Initialize attr with CL_ProcessCreateAttrInit.
562 /// \~english @par Change of internal state
563 ///        - Change of internal state according to the API does not occur.
564 /// \~english @par Conditions of processing failure
565 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
566 ///          set errno to EINVAL, -1 is returned.
567 /// \~english @par Detail
568 ///        Set process attribute to suspend forced FD close.\n
569 /// \~english @par Classification
570 ///        Public
571 /// \~english @par Type
572 ///        No match
573 /// \~english @see
574 ///        none
575 ////////////////////////////////////////////////////////////////////////////////////
576 int CL_ProcessCreateAttrSetDisableCloseFds(CL_ProcessAttr_t *attr);  // NOLINT(readability/nolint)
577
578 ////////////////////////////////////////////////////////////////////////////////////
579 /// \ingroup CL_ProcessCreateAttrSetCgroup
580 /// \~english @par Brief
581 ///        Set process attribute to Cgroup
582 /// \~english @param [in,out] attr
583 ///        const CL_ProcessAttr_t* - Process attribute pointer
584 /// \~english @param [in] cgroup_name
585 ///        const char*   - Cgroup name
586 /// \~english @par
587 ///        CL_ProcessAttr_t struct
588 /// \~english @code
589 ///                 typedef struct {
590 ///                   char body[148];
591 ///                 } CL_ProcessAttr_t;
592 ///            @endcode
593 /// \~english @retval 0 Success
594 /// \~english @retval -1 Error
595 /// \~english @par Prerequisite
596 ///        - Initialize attr with CL_ProcessCreateAttrInit.
597 ///        - cgroup specified by CL_ProcessCreateCgroupCreate() has been created.
598 /// \~english @par Change of internal state
599 ///        - Change of internal state according to the API does not occur.
600 /// \~english @par Conditions of processing failure
601 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
602 ///          set errno to EINVAL, -1 is returned.
603 ///        - When the pointer (name) to the character string hat stores the process name specified
604 ///          by the argument is NULL, set errno to EINVAL, -1 is returned.
605 ///        - When the character string length of the character string (cgroup_name) storing the process name specified
606 ///          by the argument is 64 byte or more, set errno to EINVAL, -1 is returned.
607 /// \~english @par Detail
608 ///        Set process attribute to Cgroup.\n
609 ///        Creat new Cgroup with CL_ProcessCreateCgroupCreate().\n
610 ///        An error occurs if an Cgroup name that does not exist is specified.\n
611 /// \~english @par Classification
612 ///        Public
613 /// \~english @par Type
614 ///        No match
615 /// \~english @see
616 ///        none
617 ////////////////////////////////////////////////////////////////////////////////////
618 int CL_ProcessCreateAttrSetCgroup(CL_ProcessAttr_t *attr,  // NOLINT(readability/nolint)
619                                   const char *cgroup_name);
620
621 /////////////////////////////////////////////////////////////////////////////////////
622 /// \ingroup CL_ProcessTerminate
623 /// \~english @par Brief
624 ///        Kill the process
625 /// \~english @param [in] pid
626 ///        pid_t - PID
627 /// \~english @retval int file  descriptor
628 /// \~english @retval -1 Error
629 /// \~english @par Prerequisite
630 ///        - CL_ProcessInit and CL_ProcessCreate must be running.
631 ///          (Process ID to be forcibly terminated exists)
632 /// \~english @par Change of internal state
633 ///        - Change of internal state according to the API does not occur.
634 /// \~english @par Conditions of processing failure
635 ///        - When the process ID to be forcibly terminated does not exist, -1 is returned.
636 /// \~english @par Detail
637 ///        The PID of the process is he return value (PID) of CL_ProcessCreate().
638 /// \~english @par Classification
639 ///        Public
640 /// \~english @par Type
641 ///        Open Close
642 /// \~english @see
643 ///        CL_ProcessCreate
644 /////////////////////////////////////////////////////////////////////////////////////
645 int CL_ProcessTerminate(pid_t pid);  // NOLINT(readability/nolint)
646
647 /////////////////////////////////////////////////////////////////////////////////////
648 /// \ingroup CL_ProcessTerminateGroup
649 /// \~english @par Brief
650 ///        Kill process group
651 /// \~english @param [in] pid
652 ///        pid_t - process group ID
653 /// \~english @retval int file descriptor
654 /// \~english @retval -1 Error
655 /// \~english @par Prerequisite
656 ///        - CL_ProcessInit and CL_ProcessCreate must be running.
657 ///          (Process ID to be forcibly terminated exists)
658 /// \~english @par Change of internal state
659 ///        - Change of internal state according to the API does not occur.
660 /// \~english @par Conditions of processing failure
661 ///        - When the process ID to be forcibly terminated does not exist, -1 is returned.
662 /// \~english @par Detail
663 ///        The process group ID is he return value (PID) of CL_ProcessCreate().
664 /// \~english @par Classification
665 ///        Public
666 /// \~english @par Type
667 ///        Open Close
668 /// \~english @see
669 ///        CL_ProcessCreate
670 /////////////////////////////////////////////////////////////////////////////////////
671 int CL_ProcessTerminateGroup(pid_t pid);  // NOLINT(readability/nolint)
672
673 int CL_ProcessAbort(pid_t pid);  // NOLINT(readability/nolint)
674
675 int CL_ProcessAbortGroup(pid_t pid);  // NOLINT(readability/nolint)
676
677 int CL_ProcessEuthanizeGroup(pid_t pid);  // NOLINT(readability/nolint)
678
679 /////////////////////////////////////////////////////////////////////////////////////
680 /// \ingroup CL_ProcessCleanup
681 /// \~english @par Brief
682 ///        Collect child process
683 /// \~english @param [in] sigchld_fd
684 ///        int - CL_ProcessInit() function return to fd
685 /// \~english @param [out] cleanup_info
686 ///        CL_ProcessCleanupInfo_t* - Pointer to chiled process info
687 /// \~english @par
688 ///        CL_ProcessCleanupInfo_t struct
689 /// \~english @code
690 ///                 typedef struct {
691 ///                   pid_t pid;                /* The process ID of the child. */
692 ///                   int code;                 /* signal code */
693 ///                   int status;               /* the exit status of the child or the signal */
694 ///                 } CL_ProcessCleanupInfo_t;
695 ///            @endcode
696 /// \~english @retval 0  Success
697 /// \~english @retval 1  Success
698 ///        (If WNOHANG was specified and no child(ren) specified by id has yet changed state)
699 /// \~english @retval -1 Error (setting to errno)
700 /// \~english @par Prerequisite
701 ///        - Must be runnning CL_ProcessInit.
702 /// \~english @par Change of internal state
703 ///        - Change of internal state according to the API does not occur.
704 /// \~english @par Conditions of processing failure
705 ///        - When the pointer (cleanup_info) to the child process information structure is NULL,
706 ///          set errno to EINVAL, -1 is returned.
707 ///        - When a systemu call (waitid) fails, -1 is returned.
708 ///        - When there are no child process in state waitable, set errno to EINVAL, -1 is returned.
709 /// \~english @par Detail
710 ///        This API must be called before createing a thread.\n
711 /// \~english @par
712 ///        It must be called many times while the return valu is 1.
713 ///        After the return value reaches 0, calling it again results in an error (ECHILD).\n
714 ///        The code of CL_ProcessCleanupInfo_t cotains the following value:\n
715 ///          - CLD_EXITED : Finished child process (exited)
716 ///          - CLD_KILLED : Killed child process
717 ///          - CLD_DUMPED : Ended abnormally child process
718 ///          - CLD_TRAPPED : Trapped traced child process
719 ///          - CLD_STOPPED : Stopped child process (stop)
720 ///          - CLD_CONTINUED restarted the sopped child process (after Linux 2.6.9)
721 ///          - The exit status is stored in status only when code is CLD_EXITED. Otherwise, signals are stored.
722 ///          - Need to include signal.h to use CLD_*.
723 /// \~english @par Classification
724 ///        Public
725 /// \~english @par Type
726 ///        No match
727 /// \~english @see
728 ///        none
729 ////////////////////////////////////////////////////////////////////////////////////
730 int CL_ProcessCleanup(int sigchld_fd, CL_ProcessCleanupInfo_t *cleanup_info);  // NOLINT(readability/nolint)
731
732 ////////////////////////////////////////////////////////////////////////////////////
733 /// \ingroup CL_ThreadCreate
734 /// \~english @par Brief
735 ///        Create thread
736 /// \~english @param [out] thread
737 ///        pthread_t*   - thread hadle
738 /// \~english @param [in] attr
739 ///        pthread_attr_t*   - Thread attibute pointer for pthread
740 /// \~english @param [in] cl_attr
741 ///        CL_ThreadAttr_t*   - Tred attribute pointer for expansion
742 /// \~english @param [in] start_routine
743 ///        void*(*)(void*)   - Pointer to the entry function of the thread
744 /// \~english @param [in] arg
745 ///        void*   - Argument to the entry function of the thread
746 /// \~english @par
747 ///        CL_ThreadAttr_t structure
748 /// \~english @code
749 ///                 typedef struct {
750 ///                   char body[20];
751 ///                 } CL_ThreadAttr_t;
752 ///            @endcode
753 /// \~english @retval 0 Success
754 /// \~english @retval -1 Error (set errno)
755 /// \~english @retval EAGAIN failure to create thread
756 /// \~english @par Prerequisite
757 ///        - Prerequisites are nothing.
758 /// \~english @par Change of internal state
759 ///        - Change of internal state according to the API does not occur.
760 /// \~english @par Conditions of processing failure
761 ///       - When the thread handler (thread) specified in the argument is NULL, set errno to EINVAL, -1 is returned.
762 ///       - When the pointer of the thread attribute specified in the argument is NULL,
763 ///         set errno to EINVAL, -1 is returned.
764 ///       - When the pointer (start_routine) of the entry function of the thread specified by the argument is NULL,
765 ///         set errno to EINVAL, -1 is returned.
766 ///       - Failure to initialize semaphore, set errno to sem_init, -1 is returned.
767 ///       - Failure to create thread (pthread_create), EAGAIN is returned.
768 ///       - Failure to rock semaphore (sem_wait), set errno to sem_init, -1 is returned.
769 /// \~english @par Detail
770 ///        Create thread.\n
771 ///        The extension thread attribute (cl_attr) is used o assign the thread name set
772 ///        by CL_ThreadCreateAttrSetName(CL_ThreadAttr_t*, const char*).\n
773 /// \~english @par Classification
774 ///        Public
775 /// \~english @see
776 ///        none
777 ////////////////////////////////////////////////////////////////////////////////////
778 int CL_ThreadCreate(pthread_t *thread, pthread_attr_t *attr,  // NOLINT(readability/nolint)
779                     CL_ThreadAttr_t *cl_attr, void *(*start_routine)(void *),
780                     void *arg);
781
782 ////////////////////////////////////////////////////////////////////////////////////
783 /// \ingroup CL_ThreadCreateAttrInit
784 /// \~english @par Brief
785 ///        Initialize thread attribute
786 /// \~english @param [out] attr
787 ///        CL_ThreadAttr_t*   - thread attribute pointer
788 /// \~english @par
789 ///        CL_ThreadAttr_t structure
790 /// \~english @code
791 ///                 typedef struct {
792 ///                   char body[20];
793 ///                 } CL_ThreadAttr_t;
794 ///            @endcode
795 /// \~english @retval 0 Success
796 /// \~english @retval -1 Error (set errno)
797 /// \~english @par Prerequisite
798 ///        - Prerequisites are nothing.
799 /// \~english @par Change of internal state
800 ///        - Change of internal state according to the API does not occur.
801 /// \~english @par Conditions of processing failure
802 ///       - When the pointer (attr) of the thread attributespecified by the argument is NULL, set errno to EINVAL, -1 is returned.
803 /// \~english @par Detail
804 ///       Initialize structure CL_ThreadAttr_t that stores threade attribute.\n
805 /// \~english @par Classification
806 ///        Public
807 /// \~english @see
808 ///        none
809 ////////////////////////////////////////////////////////////////////////////////////
810 int CL_ThreadCreateAttrInit(CL_ThreadAttr_t *attr);  // NOLINT(readability/nolint)
811
812 ////////////////////////////////////////////////////////////////////////////////////
813 /// \ingroup CL_ThreadCreateAttrSetName
814 /// \~english @par Brief
815 ///        Set thread attribute to thread name
816 /// \~english @param [out] attr
817 ///        CL_ThreadAttr_t*   - thread attribute pointer
818 /// \~english @param [in] name
819 ///        const char*   - Pointer to the string storing the thread name (max length 16byte)
820 /// \~english @par
821 ///        CL_ThreadAttr_t structure
822 /// \~english @code
823 ///                 typedef struct {
824 ///                   char body[20];
825 ///                 } CL_ThreadAttr_t;
826 ///            @endcode
827 /// \~english @retval 0 Success
828 /// \~english @retval -1 Error (set errno)
829 /// \~english @par Prerequisite
830 ///        - Prerequisites are nothing.
831 /// \~english @par Change of internal state
832 ///        - Change of internal state according to the API does not occur.
833 /// \~english @par Conditions of processing failure
834 ///       - When the pointer (attr) of thread attribute specified by the argument is NULL, set errno to EINVAL, -1 is returned.
835 ///       - When the pointer (name) to the character string that stores the thread name specified
836 ///         by the argument is NULL, set errno to EINVAL, -1 is returned.
837 /// \~english @par Detail
838 ///       Set thread attribute to thread name\n
839 ///       The characer string that stores the thread name specified by the argument must satisfy the following conditions:\n
840 ///       - Terminated by a NULL.\n
841 ///       - The maximum lengthof character string is 16 byte including the termination character.\n
842 /// \~english @par Classification
843 ///        Public
844 /// \~english @see
845 ///        none
846 ////////////////////////////////////////////////////////////////////////////////////
847 int CL_ThreadCreateAttrSetName(CL_ThreadAttr_t *attr, const char *name);  // NOLINT(readability/nolint)
848
849 ////////////////////////////////////////////////////////////////////////////////////
850 /// \ingroup CL_ProcessCreateCgroupCreate
851 /// \~english @par Brief
852 ///        Create Cgroup
853 /// \~english @param [in] cgroup_name
854 ///        const char* - cgroup name
855 /// \~english @param [in] attr
856 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribut
857 /// \~english @par
858 ///        CL_ProcessCreateCgroupAttr_t struct
859 /// \~english @code
860 ///                 typedef struct {
861 ///                   char body[24];
862 ///                 } CL_ProcessCreateCgroupAttr_t;
863 ///            @endcode
864 /// \~english @retval 0 Success
865 /// \~english @retval -1 Error
866 /// \~english @par Prerequisite
867 ///        - Initialize attr by CL_ProcessCreateCgroupAttrInit
868 /// \~english @par Change of internal state
869 ///        - Change of internal state according to the API does not occur.
870 /// \~english @par Conditions of processing failure
871 ///       - When the Cgroup name (cgroup_name) specified by the argument is NULL, set errno to EINVAL, -1 is returned.
872 ///       - When the pointer (attr) of the Cgroup attribute specified by the argumet is NULL,
873 ///         set errno to EINVAL, -1 is returned.
874 ///       - When the area for directory path name of the CPU subsystem of Cgroup could not be allocated,
875 ///         set errno to EINVAL, -1 is returned.
876 ///       - When the area for directory of the CPU subsystem of Cgroup could not be create, -1 is returned.
877 ///       - When the area for file path name of the CPU subsystem of Cgroup could not be allocated,
878 ///         set errno to EINVAL, -1 is returned.
879 ///       - When file descriptor of the CPU subsystem of Cgroup could not be acquired, -1 is returned.
880 ///       - When setting value to CPU subsystem of Cgroup could not be written, -1 is returned.
881 ///       - When the area for directory path name of the memory subsystem of Cgroup could not be allocated,
882 ///         set errno to EINVAL, -1 is returned.
883 ///       - When the area for directory of the memory subsystem of Cgroup could not be create, -1 is returned.
884 ///       - When the area for file path name of the memory subsystem of Cgroup could not be allocated,
885 ///         set errno to EINVAL, -1 is returned.
886 ///       - When file descriptor of the memory subsystem of Cgroup could not be acquired, -1 is returned.
887 ///       - When setting value to memory subsystem of Cgroup could not be written, -1 is returned.
888 /// \~english @par Detail
889 ///        Create Cgroup to which the process to be created belongs.
890 ///        If it belongs to Cgroup that has already been created, it is not necessary to create it.\n
891 /// \~english @par
892 ///        Since the Cgroup attribute cannot be changed during Cgroup, if it is necessary o chage the Cgroup attribute,
893 ///        it is necessary to call the following API and change the Cgroup attribute calling this API.\n
894 ///          - CL_ProcessCreateCgroupAttrInit :Initialize Cgroup attribute
895 ///          - CL_ProcessCreateCgroupAttrSetCfsBandwidthControl :TSS process CPU time control by Bandwidth Control
896 ///          - CL_ProcessCreateCgroupAttrSetCpuShares :TSS process CPU time control
897 ///          - CL_ProcessCreateCgroupAttrSetMemoryLimit :Contol memory usage
898 ///          - CL_ProcessCreateCgroupAttrSetMemoryUsageNotification :Memory usage notification setting
899 ///          - CL_ProcessCreateCgroupAttrSetRtThrottling :FIFO/RR process CPU time control
900 /// \~english @par Classification
901 ///        Public
902 /// \~english @par Type
903 ///        Open Close
904 /// \~english @see
905 ///        CL_ProcessCreateCgroupDelete,
906 ///        CL_ProcessCreateCgroupAttrInit, CL_ProcessCreateCgroupAttrSetCfsBandwidthControl,
907 ///        CL_ProcessCreateCgroupAttrSetCpuShares, CL_ProcessCreateCgroupAttrSetMemoryLimit,
908 ///        CL_ProcessCreateCgroupAttrSetMemoryUsageNotification, CL_ProcessCreateCgroupAttrSetRtThrottling,
909 ////////////////////////////////////////////////////////////////////////////////////
910 int CL_ProcessCreateCgroupCreate(const char *cgroup_name,  // NOLINT(readability/nolint)
911                                  CL_ProcessCreateCgroupAttr_t *attr);
912
913 ////////////////////////////////////////////////////////////////////////////////////
914 /// \ingroup CL_ProcessCreateCgroupAttrInit
915 /// \~english @par Brief
916 ///        Initialize Cgroup attribute
917 /// \~english @param [out] attr
918 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer
919 /// \~english @par
920 ///        CL_ProcessCreateCgroupAttr_t struct
921 /// \~english @code
922 ///                 typedef struct {
923 ///                   char body[24];
924 ///                 } CL_ProcessCreateCgroupAttr_t;
925 ///            @endcode
926 /// \~english @retval 0 Success
927 /// \~english @retval -1 Error
928 /// \~english @par Prerequisite
929 ///        - Prerequisites are nothing.
930 /// \~english @par Change of internal state
931 ///        - Change of internal state according to the API does not occur.
932 /// \~english @par Conditions of processing failure
933 ///       - When the pointer of Cgroup attribute (attr) specified in the arguments is NULL, set errno to EINVAL, -1 is returned.
934 /// \~english @par Detail
935 ///       Initialize Cgroup attibute with 0.\n
936 /// \~english @par Classification
937 ///        Public
938 /// \~english @par Type
939 ///        No match
940 /// \~english @see
941 ///        none
942 ////////////////////////////////////////////////////////////////////////////////////
943 int CL_ProcessCreateCgroupAttrInit(CL_ProcessCreateCgroupAttr_t *attr);  // NOLINT(readability/nolint)
944
945 ////////////////////////////////////////////////////////////////////////////////////
946 /// \ingroup CL_ProcessCreateCgroupAttrSetRtThrottling
947 /// \~english @par Brief
948 ///        Set FIFO/RR process CPU time control
949 /// \~english @param [in,out] attr
950 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute
951 /// \~english @param [in] runtime_us
952 ///        int - CPU allocation time(us)
953 /// \~english @par
954 ///        CL_ProcessCreateCgroupAttr_t struct
955 /// \~english @code
956 ///                 typedef struct {
957 ///                   char body[24];
958 ///                 } CL_ProcessCreateCgroupAttr_t;
959 ///            @endcode
960 /// \~english @retval 0 Success
961 /// \~english @retval -1 Error
962 /// \~english @par Prerequisite
963 ///        - Initialize attr with CL_ProcessCreateCgroupAttrInit.
964 /// \~english @par Change of internal state
965 ///        - Change of internal state according to the API does not occur.
966 /// \~english @par Conditions of processing failure
967 ///        - When the pointer of Cgroup attribute (attr) specified in the arguments is NULL,
968 ///          set errno to EINVAL, -1 is returned.
969 /// \~english @par Detail
970 ///        Limiting the CPU time allocated to a process to
971 ///        which a real-time class schedule policy (SCHED_FIFO/SCHED_RR) is applied.\n
972 ///        Set the value of argument runtime_us to the cpu.rt_runtime_us (CPU allocation time) of created Cgroup.\n
973 ///        cpu.rt_period_us(unit time:1000000us) is not changed.\n
974 ///        If not set, Cgroup created will remain at default (CPU allocation time:950000us).\n
975 ///        The configurable range of runtime_us depends on the use of Cgroup and the kernel version.
976 ///        The user sets an appropriate value.\n
977 /// \~english @par Classification
978 ///        Public
979 /// \~english @par Type
980 ///        No match
981 /// \~english @see
982 ///        none
983 ////////////////////////////////////////////////////////////////////////////////////
984 int CL_ProcessCreateCgroupAttrSetRtThrottling(  // NOLINT(readability/nolint)
985     CL_ProcessCreateCgroupAttr_t *attr, int runtime_us);
986
987 ////////////////////////////////////////////////////////////////////////////////////
988 /// \ingroup CL_ProcessCreateCgroupAttrSetCpuShares
989 /// \~english @par Brief
990 ///        Set TSS process CPU time control
991 /// \~english @param [in,out] attr
992 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer
993 /// \~english @param [in] cpu_shares
994 ///        int - An integer value that sepcified the relative distribution of CPU time
995 /// \~english @par
996 ///        CL_ProcessCreateCgroupAttr_t struct
997 /// \~english @code
998 ///                 typedef struct {
999 ///                   char body[24];
1000 ///                 } CL_ProcessCreateCgroupAttr_t;
1001 ///            @endcode
1002 /// \~english @retval 0 Success
1003 /// \~english @retval -1 Error
1004 /// \~english @par Prerequisite
1005 ///        - Initialize attr with CL_ProcessCreateCgroupAttrInit
1006 /// \~english @par Change of internal state
1007 ///        - Change of internal state according to the API does not occur.
1008 /// \~english @par Conditions of processing failure
1009 ///        - When the pointer (attr) of the Cgroup attribute specified by the argument is NULL,
1010 ///          set errno to EINVAL, -1 is returned.
1011 /// \~english @par Detail
1012 ///        Cotrols the CPU time allocated to a process to which
1013 ///        a class TSS schedule policy (SCHED_OTHER, etc.) is applied.\n
1014 ///        If cpu_shares is set with this function, a single Cgroup is created and cpu.shares is set with that value.\n
1015 ///        If not set, remain at default.\n
1016 ///        cpu_shares is set to the standard value 1024, and CPU time is allocated according
1017 ///        to the allocaion value specified between Cgroup.\n
1018 ///        Task Cgroup with cpu.shares set to 1024 has twice as much CPU time as
1019 ///        task Cgroup with cpu.shares set to 512.\n
1020 ///        Processes belonging to the same Cgroup are equally allocated CPU time allocated to Cgroup.\n
1021 ///        Note that the time distribution is distributed across al CPU cores on a multi-core system.\n
1022 ///        In a multicore system, if Cgroup limit is set to 100% of the CPU,
1023 ///        100% of each CPU core wil be available.\n\n
1024 ///        Examle) If Cgroup A is set to use 25% of the CPU and Cgroup B is set to use 75% of the CPU,\n
1025 ///        and a process that uses CPU intensively is started on a 4-core system (1 process in A and 3 processes in B),\n
1026 ///        the CPU allocaion is distributed as follows.\n\n
1027 /// \~english @par
1028 ///        | PID | cgroup | CPU | CPU allotment |
1029 ///        |:---:|:------:|:---:|:-------:|
1030 ///        | 100 | A | 0 | CPU0 100% |
1031 ///        | 101 | B | 1 | CPU1 100% |
1032 ///        | 102 | B | 2 | CPU2 100% |
1033 ///        | 103 | B | 3 | CPU3 100% |
1034 /// \~english @par
1035 /// \~english @par Classification
1036 ///        Public
1037 /// \~english @par Type
1038 ///        No match
1039 /// \~english @see
1040 ///        none
1041 ////////////////////////////////////////////////////////////////////////////////////
1042 int CL_ProcessCreateCgroupAttrSetCpuShares(CL_ProcessCreateCgroupAttr_t *attr,  // NOLINT(readability/nolint)
1043                                            int cpu_shares);
1044
1045 ///////////////////////////////////////////////////////////////////////////////////
1046 /// \ingroup CL_ProcessCreateCgroupAttrSetCfsBandwidthControl
1047 /// \~english @par Brief
1048 ///        Set TS process CU time control by Bandwidth Control
1049 /// \~english @param [in,out] attr
1050 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer
1051 /// \~english @param [in] cfs_quota_us
1052 ///        int - CPU allocation time
1053 /// \~english @par
1054 ///        CL_ProcessCreateCgroupAttr_t struct
1055 /// \~english @code
1056 ///                 typedef struct {
1057 ///                   char body[24];
1058 ///                 } CL_ProcessCreateCgroupAttr_t;
1059 ///            @endcode
1060 /// \~english @retval 0 Success
1061 /// \~english @retval -1 Error
1062 /// \~english @par Prerequisite
1063 ///        - Initialize attr with CL_ProcessCreateCgroupAttrInit
1064 /// \~english @par Change of internal state
1065 ///        - Change of internal state according to the API does not occur.
1066 /// \~english @par Conditions of processing failure
1067 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
1068 ///          set errno to EINVAL, -1 is returned.
1069 /// \~english @par Detail
1070 ///        Controls the amount of time allocated to processes o whitch TSS class schedule plicy (SCHED_OTHER, etc.) are
1071 ///        applied using bandwidth control of CFS(Completely Fair Scheduler) implemented from kernel 3.2.\n
1072 ///        Set the value of argument cfs_quota_us to the cpu.cfs_quota_us of created Cgroup.\n
1073 ///        cpu.cfs_period_us(unit time:1000000us) is not changed.\n
1074 ///        If not set, the created Cgroup will not have CPU allocatio control. (set cpu.cfs_guota_us to -1).\n
1075 ///        The time (%) allocated to Cgroup can be set correctly,
1076 ///        and it can be allocated correctly if the CPU is free.\n
1077 ///        It is scheduled to be allocated as much as possible even if it conflicts with other Cgroup's.\n
1078 /// \~english @par Classification
1079 ///        Public
1080 /// \~english @par Type
1081 ///        No match
1082 /// \~english @see
1083 ///        none
1084 ////////////////////////////////////////////////////////////////////////////////////
1085 int CL_ProcessCreateCgroupAttrSetCfsBandwidthControl(  // NOLINT(readability/nolint)
1086     CL_ProcessCreateCgroupAttr_t *attr, int cfs_quota_us);
1087
1088 /////////////////////////////////////////////////////////////////
1089 /// \ingroup CL_ProcessCreateCgroupAttrSetMemoryLimit
1090 /// \~english @par Brief
1091 ///        Control memory usage
1092 /// \~english @param [in,out] attr
1093 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer
1094 /// \~english @param [in] memory_limit
1095 ///        int - memory limit (byte)
1096 /// \~english @par
1097 ///        CL_ProcessCreateCgroupAttr_t struct
1098 /// \~english @code
1099 ///                 typedef struct {
1100 ///                   char body[24];
1101 ///                 } CL_ProcessCreateCgroupAttr_t;
1102 ///            @endcode
1103 /// \~english @retval 0 Success
1104 /// \~english @retval -1 Error
1105 /// \~english @par Prerequisite
1106 ///        - Initialize attr with CL_ProcessCreateCgroupAttrInit
1107 /// \~english @par Change of internal state
1108 ///        - Change of internal state according to the API does not occur.
1109 /// \~english @par Conditions of processing failure
1110 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
1111 ///          set errno to EINVAL, -1 is returned.
1112 /// \~english @par Detail
1113 ///        Control the CPU time allocated to a process.\n
1114 ///        Set the value of argument memory_limit to the memory.limit_in_bytes of created Cgroup.\n
1115 ///        If not set, there is no memory limit.When a request exceeding the memory limit is issued,
1116 ///        a SIGKILL is sent from the kernel and the process is discarded.
1117 ///        Note: When the memory limit is exceeded, control moves to 00M,
1118 ///        but its operation ca be changed (Documentation/cgroup/memory.txt).\n
1119 ///        Write memory.oom_control to 1 to stop the OOM-Killer.
1120 ///        When OOM-Killer is stopped, the task below Cgroup becomes hang/sleep.\n
1121 ///        The task moves when the limit of the memory Cgroup increaes or when usage decreases. When usage decreases,\n
1122 ///        - Task was killed\n
1123 ///        - Task was moved other group\n
1124 ///        - File has been deleted\n
1125 /// \~english @par
1126 ///       You can also receive a eventf notification from OOM.\n
1127 ///       Memory usage is counted as follows\n
1128 ///        - RSS(All mapped anon pages)\n
1129 ///        - Page Cache\n
1130 ///        - First acess Shared Pages in Cgroup\n
1131 /// \~english @par Classification
1132 ///        Public
1133 /// \~english @par Type
1134 ///        No match
1135 /// \~english @see
1136 ///        none
1137 ////////////////////////////////////////////////////////////////////////////////////
1138 int CL_ProcessCreateCgroupAttrSetMemoryLimit(CL_ProcessCreateCgroupAttr_t *attr,  // NOLINT(readability/nolint)
1139                                              int memory_limit);
1140
1141 ////////////////////////////////////////////////////////////////////////////////////
1142 /// \ingroup CL_ProcessCreateCgroupAttrSetMemoryUsageNotification
1143 /// \~english @par Brief
1144 ///        Set notificatio when memory usage exceeds the specified amount
1145 /// \~english @param [in,out] attr
1146 ///        const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer
1147 /// \~english @param [in] usage_in_bytes
1148 ///        int - usage in bytes(byte)
1149 /// \~english @param [in] event_fd
1150 ///        int - File dexcriptor created by system call eventfd()
1151 /// \~english @par
1152 ///        CL_ProcessCreateCgroupAttr_t struct
1153 /// \~english @code
1154 ///                 typedef struct {
1155 ///                   char body[24];
1156 ///                 } CL_ProcessCreateCgroupAttr_t;
1157 ///            @endcode
1158 /// \~english @retval 0 Success
1159 /// \~english @retval -1 Error
1160 /// \~english @par Prerequisite
1161 ///        - Initialize attr with CL_ProcessCreateCgroupAttrInit
1162 /// \~english @par Change of internal state
1163 ///        - Change of internal state according to the API does not occur.
1164 /// \~english @par Conditions of processing failure
1165 ///        - When the pointer of the process attribute specified (attr) in the argument is NULL,
1166 ///          set errno to EINVAL, -1 is returned.
1167 ///        - When event_fd is negative for a file descriptor created by system call eventfd(),
1168 ///          set errno to EINVAL, -1 is returned.
1169 /// \~english @par Detail
1170 ///        event_fd is notifued when memory usage exceeds argument usage_in_bytes.\n
1171 ///        See eventfd for details of event_fd.\n
1172 /// \~english @par Classification
1173 ///        Public
1174 /// \~english @par Type
1175 ///        No match
1176 /// \~english @see
1177 ///        none
1178 ////////////////////////////////////////////////////////////////////////////////////
1179 int CL_ProcessCreateCgroupAttrSetMemoryUsageNotification(  // NOLINT(readability/nolint)
1180     CL_ProcessCreateCgroupAttr_t *attr, int usage_in_bytes, int event_fd);
1181
1182 ////////////////////////////////////////////////////////////////////////////////////
1183 /// \ingroup CL_ProcessCreateCgroupDelete
1184 /// \~english @par Brief
1185 ///        Delete Cgroup
1186 /// \~english @param [in] cgroup_name
1187 ///        const char* - cgroup name
1188 /// \~english @retval 0 Success
1189 /// \~english @retval -1 Error
1190 /// \~english @par Prerequisite
1191 ///        - Need to be runnning CL_ProcessCreateCgroupCreate.
1192 /// \~english @par Change of internal state
1193 ///        - Change of internal state according to the API does not occur.
1194 /// \~english @par Conditions of processing failure
1195 ///        - When the Cgroup (cgroup_name) name specified inthe argument is NULL, set errno to EINVAL, -1 is returned.
1196 ///        - When the area for directory path name of the CPU subsystem of Cgroup and
1197 ///          memory subsystem of Cgroup could not be allocated,  set errno to EINVAL, -1 is returned.
1198 ///        - When the area for the directory path name of the memory subsystem of Cgroup cannot be allocated and
1199 ///          the directory for the CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned.
1200 ///        - When the directory for the CPU subsystem of Cgroup does not exist and
1201 ///          the area for the directory path name of the memory subsystem of Cgroup cannot be allocated,
1202 ///          set errno to EINVAL, -1 is returned.
1203 ///        - When the directory for the memory subsystem of Cgroup and
1204 ///          the directory for the CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned.
1205 ///        - When the directory for the memory subsystem of Cgroup could not be deleted, -1 is returned.
1206 ///        - When the directory for the CPU subsystem of Cgroup could not be deleted, -1 is returned.
1207 /// \~english @par Detail
1208 ///        Delete Cgroup. If there is a proess belonging to Cgroup, error code (EBUSY) is returned.\n
1209 /// \~english @par
1210 ///        Success is also notified in the following cases:\n
1211 ///        - When the area for directory path name of memory subsyste Cgroup could not be allocated
1212 ///          but CPU subsystem of Cgroup was deleted successfully.
1213 ///        - When the directory for the memory subsystem of Cgroup does not exist,
1214 ///          but CPU subsystem of Cgroup was deleted successfully.
1215 ///        - When the area for directory path name of CPU subsyste Cgroup could not be allocated
1216 ///          but memory subsystem of Cgroup was deleted successfully.
1217 ///        - When the directory for the CPU subsystem of Cgroup does not exist,
1218 ///          but memory subsystem of Cgroup was deleted successfully.
1219 /// \~english @par Classification
1220 ///        Public
1221 /// \~english @par Type
1222 ///        Open Close
1223 /// \~english @see
1224 ///        CL_ProcessCreateCgroupCreate
1225 ////////////////////////////////////////////////////////////////////////////////////
1226 int CL_ProcessCreateCgroupDelete(const char *cgroup_name);  // NOLINT(readability/nolint)
1227
1228 ////////////////////////////////////////////////////////////////////////////////////
1229 /// \ingroup CL_ProcessCreateCgroupClassify
1230 /// \~english @par Brief
1231 ///        Move process to the Cgroup
1232 /// \~english @param [in,out] cgroup_name
1233 ///        const char* - Destination A name
1234 /// \~english @param [in] pid
1235 ///        pid_t - process ID
1236 /// \~english @retval 0 Success
1237 /// \~english @retval -1 Error
1238 /// \~english @par Prerequisite
1239 ///        - Need to be running CL_ProcessCreateCgroupCreate.
1240 /// \~english @par Change of internal state
1241 ///        - Change of internal state according to the API does not occur.
1242 /// \~english @par Conditions of processing failure
1243 ///        - When the Cgroup (cgroup_name) specified in the argument is NULL, set errno to EINVAL, -1 is returned.
1244 ///        - When the area for directory path name of memory subsystem of Cgroup and
1245 ///          CPU subsystem of Cgroup could not be allocated, set errno to EINVAL, -1 is returned.
1246 ///        - When the area for directory path name of memory subsystem of Cgroup could not be allocated,
1247 ///          and the directory for CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned.
1248 ///        - When the directory for memory subsystem of Cgroup does not exist and
1249 ///          the directory for CU subsystem of Cgroup could not allocated , set errno to EINVAL, -1 is returned.
1250 ///        - When the directory for the memory subsystem of Cgroup and
1251 ///          the directory for the CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned.
1252 ///        - When the area for directory path name of the memory subsystem of Cgroup could not allocated,
1253 ///          set errno to EINVAL, -1 is returned.
1254 ///        - When the file descripter for the memory subsystem of Cgroup could not be obtained, -1 is returned.
1255 ///        - When pid could not be written to the file for memory subsystem of Cgroup, -1 is returned.
1256 ///        - When the area for directory path name of the CPU subsystem of Cgroup could not be allocated,
1257 ///          set errno to EINVAL, -1 is returned.
1258 ///        - When the file decsripter for the CPU subsystem of Cgroup could not be allocated, -1 is returned.
1259 ///        - When pid could not be written to the file for CPU subsystem of Cgroup, -1 is returned.
1260 /// \~english @par Detail
1261 ///        Move process to the Cgroup.\n
1262 /// \~english @par
1263 ///        Success is also notified in the following cases:\n
1264 ///        - When the area for directory path name of memory subsyste Cgroup could not be allocated
1265 ///          but CPU subsystem of Cgroup was deleted successfully.
1266 ///        - When the directory for the memory subsystem of Cgroup does not exist,
1267 ///          but CPU subsystem of Cgroup was deleted successfully.
1268 ///        - When the area for directory path name of CPU subsyste Cgroup could not be allocated
1269 ///          but memory subsystem of Cgroup was deleted successfully.
1270 ///        - When the directory for the CPU subsystem of Cgroup does not exist,
1271 ///          but memory subsystem of Cgroup was deleted successfully.
1272 /// \~english @par Classification
1273 ///        Public
1274 /// \~english @par Type
1275 ///        No match
1276 /// \~english @see
1277 ///        none
1278 ////////////////////////////////////////////////////////////////////////////////////
1279 int CL_ProcessCreateCgroupClassify(const char *cgroup_name, pid_t pid);  // NOLINT(readability/nolint)
1280
1281 /** @}*/  // end of common_library
1282 /** @}*/  // end of NativeService
1283 /** @}*/  // end of BaseSystem
1284 #ifdef __cplusplus
1285 }
1286 #endif
1287
1288 #endif  // #ifndef _cl_process_h_  // NOLINT(build/header_guard)