My Project
Functions
plist.h File Reference

Linked List for maintaining process id - command line pairs. More...

#include <sys/types.h>

Go to the source code of this file.

Functions

int insertElement (pid_t pid, const char *commandLine)
 Inserts a new pid-command line pair into the linked list. More...
 
int removeElement (pid_t pid, char *commandLineBuffer, size_t bufferSize)
 Remove a specific pid-command line pair from the linked list. More...
 
void walkList (int(*callback)(pid_t, const char *))
 Invokes a callback function on each element in the list. More...
 

Detailed Description

Linked List for maintaining process id - command line pairs.

This implementation is not thread safe.

Function Documentation

◆ insertElement()

int insertElement ( pid_t  pid,
const char *  commandLine 
)

Inserts a new pid-command line pair into the linked list.

During the insert operation, the passed commandLine is copied to an internally allocated buffer. The caller may free or otherwise reuse the memory occupied by commandLine after return from insertElement.

Parameters
pidThe process id of the pair that is to be inserted.
commandLineThe commandLine corresponding to the process with id pid.
Returns
pid on success, negative value on error
Return values
pidsuccess
-1a pair with the given pid already exists
-2insufficient memory to complete the operation

◆ removeElement()

int removeElement ( pid_t  pid,
char *  commandLineBuffer,
size_t  bufferSize 
)

Remove a specific pid-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, removeElement deallocates all resources that were occupied by the removed pair.

Parameters
pidThe process id of the pair that is to be removed.
commandLineBufferA buffer provided by the caller that the '\0'-terminated commandline is written to.
bufferSizeThe size of commandLineBuffer.
Returns
actual length of the command line on success, negative value on error.
Return values
>0success, actual length of the command line
-1a pair with the given pid does not exist

◆ walkList()

void walkList ( int(*)(pid_t, const char *)  callback)

Invokes a callback function on each element in the list.

The callback function is passed the pid-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.
Parameters
callbackPointer to the function to be invoked for each list element.