---
name: "gearman_execute"
section: "3"
platform: "linux"
package: "gearmand"
version: "2.2.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/gearman_execute"
---

# gearman\_execute(3)

Gearmand Documentation, https://gearman.org/gearmand/

## NAME

gearman\_execute - Gearmand Documentation, https://gearman.org/gearmand/

## SYNOPSIS

\#include \<libgearman/gearman.h\>

- ***gearman\_task\_st* \*gearman\_execute(*gearman\_client\_st* \*client, const char \*function\_name, *size\_t* function\_name\_length, const char \*unique, *size\_t* unique\_length, *gearman\_work\_t* \*workload, *gearman\_argument\_t* \*arguments, void \*context)**

  - ***gearman\_task\_st* \*gearman\_execute\_by\_partition(*gearman\_client\_st* \*client, const char \*partition\_function, const *size\_t* partition\_function\_length, const char \*function\_name, const *size\_t* function\_name\_length, const char \*unique\_str, const *size\_t* unique\_length, *gearman\_work\_t* \*workload, *gearman\_argument\_t* \*arguments, void \*context)**

  Link with -lgearman

## DESCRIPTION

*gearman\_execute()* is used to create a new *gearman\_task\_st* that is executed against the function that is found via the function\_name argument.

*gearman\_work\_t* can be used to describe the work that will be executed, it is built with *gearman\_argument\_make()*.  The argument unique\_str is optional, but if supplied it is used for coalescence by **gearmand**.

*gearman\_argument\_t* is the work that the *client* will send the to the server

If *gearman\_execute()* is given a *gearman\_work\_t* that has been built with a reducer, it takes the *gearman\_argument\_t* and executs it against a *function* as it normally would, but it tells the function to then process the results through a *reducer* function that the *gearman\_work\_t* was created with.

What is happening is that the function is mappping/splitting work up into units, and then sending each of them to the reducer function. Once all work is completed, the *mapper* function will aggregate the work via an aggregator function, *gearman\_aggregator\_fn*, and return a result.

If any of the units of work error, the job will be aborted. The resulting value will be stored in the *gearman\_task\_st*.

The result can be obtained from the task by calling *gearman\_task\_result()* to gain the *gearman\_result\_st*.

## RETURN VALUE

*gearman\_execute()* returns a c:type:*gearman\_task\_st*.

## EXAMPLE

```
/*
  Example code to show how to send a string to a function called "reverse" and print the results.
*/
/*
# Gearman server and library
# Copyright (C) 2012 Data Differential, http://datadifferential.com/
# All rights reserved.
#
# Use and distribution licensed under the BSD license.  See
# the COPYING file in this directory for full text.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <libgearman/gearman.h>
int main(void)
{
  gearman_client_st *client= gearman_client_create(NULL);
  gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
  if (gearman_failed(ret))
  {
    return EXIT_FAILURE;
  }
  gearman_argument_t value= gearman_argument_make(0, 0, "Reverse Me", strlen("Reverse Me"));
  gearman_task_st *task= gearman_execute(client,
                                         "reverse", strlen("reverse"),  // function
                                         NULL, 0,  // no unique value provided
                                         NULL,
                                         &value, 0);
  if (task == NULL) // If gearman_execute() can return NULL on error
  {
    fprintf(stderr, "Error: %s\n", gearman_client_error(client));
    gearman_client_free(client);
    return EXIT_FAILURE;
  }
  // Make sure the task was run successfully
  if (gearman_success(gearman_task_return(task)))
  {
    // Make use of value
    gearman_result_st *result= gearman_task_result(task);
    printf("%.*s\n", (int)gearman_result_size(result), gearman_result_value(result));
  }
  gearman_client_free(client);
  return EXIT_SUCCESS;
}
```

## HOME

To find out more information please check: *https://gearman.org/gearmand/*

## SEE ALSO

**[gearmand(8)](/gearmand/8.md)** **[libgearman(3)](/libgearman/3.md)**

## AUTHOR

Data Differential http://www.datadifferential.com/

## COPYRIGHT

2011-2014, Data Differential, http://www.datadifferential.com/
