Linked list for maintaining (process ID, command line) pairs. More...
#include <sys/types.h>Go to the source code of this file.
Functions | |
| int | plistAdd (pid_t pid, const char cmdLine[]) |
| Inserts a new (process ID, command line) pair into the linked list. | |
| int | plistRemove (pid_t pid, char cmdLineBuffer[], size_t bufferSize) |
| Removes a specific (process ID, command line) pair from the linked list. | |
| void | plistIterate (int(*callback)(pid_t, const char *)) |
| Invokes a callback function on each element in the list. | |
Linked list for maintaining (process ID, command line) pairs.
| int plistAdd | ( | pid_t | pid, | |
| const char | cmdLine[] | |||
| ) |
Inserts a new (process ID, command line) pair into the linked list.
During the insert operation, the passed cmdLine is copied to an internally allocated buffer. The caller may free or otherwise reuse the memory occupied by cmdLine after return from plistAdd().
| pid | The process id of the pair that is to be inserted. | |
| cmdLine | The command line corresponding to the process with ID pid. |
| pid | Success. | |
| -1 | A pair with the given pid already exists. | |
| -2 | Insufficient memory to complete the operation. |
| void plistIterate | ( | int(*)(pid_t, const char *) | callback | ) |
Invokes a callback function on each element in the list.
The callback function is passed the (process ID, command line) pair for the current list element. The callback function shall return 0 to request further processing of the list. Any other return value will cause the early termination of the list walk. The callback function must not modify the process list.
| callback | Pointer to the function to be invoked for each list element. |
| int plistRemove | ( | pid_t | pid, | |
| char | cmdLineBuffer[], | |||
| size_t | bufferSize | |||
| ) |
Removes a specific (process ID, command line) pair from the linked list.
The linked list is searched for a pair with the given pid. If such a pair is found, the '\0'-terminated command line is copied to the buffer provided by the caller. If the length of the command line exceeds the size of the buffer, only the first (bufferSize - 1) characters of the command line are copied to the buffer and terminated with the '\0' character. Upon completion, plistRemove() deallocates all resources that were occupied by the removed pair.
| pid | The process ID of the pair that is to be removed. | |
| cmdLineBuffer | A buffer provided by the caller that the '\0'-terminated command line is written to. | |
| bufferSize | The size of cmdLineBuffer. |
| >0 | Success, actual length of the command line. | |
| -1 | A pair with the given pid does not exist. |
1.7.1