{"id":17002050,"url":"https://github.com/sagiegurari/c_forever","last_synced_at":"2025-04-12T06:21:48.000Z","repository":{"id":139264121,"uuid":"258730432","full_name":"sagiegurari/c_forever","owner":"sagiegurari","description":"Ensure the program runs continuously.","archived":false,"fork":false,"pushed_at":"2023-09-27T07:11:04.000Z","size":51,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T01:41:29.397Z","etag":null,"topics":["c","c-lib","c-library","forever"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagiegurari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-04-25T09:12:07.000Z","updated_at":"2023-05-16T12:00:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"2c6c1809-7d1a-44b2-a728-719f60a2731e","html_url":"https://github.com/sagiegurari/c_forever","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fc_forever","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fc_forever/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fc_forever/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Fc_forever/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagiegurari","download_url":"https://codeload.github.com/sagiegurari/c_forever/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525775,"owners_count":21118750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-lib","c-library","forever"],"created_at":"2024-10-14T04:26:57.159Z","updated_at":"2025-04-12T06:21:47.970Z","avatar_url":"https://github.com/sagiegurari.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# forever\n\n[![CI](https://github.com/sagiegurari/c_forever/workflows/CI/badge.svg?branch=master)](https://github.com/sagiegurari/c_forever/actions)\n[![Release](https://img.shields.io/github/v/release/sagiegurari/c_forever)](https://github.com/sagiegurari/c_forever/releases)\n[![license](https://img.shields.io/github/license/sagiegurari/c_forever)](https://github.com/sagiegurari/c_forever/blob/master/LICENSE)\n\n\u003e Ensure the program runs continuously.\n\n* [Overview](#overview)\n* [Usage](#usage)\n* [Contributing](.github/CONTRIBUTING.md)\n* [Release History](CHANGELOG.md)\n* [License](#license)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n## Overview\nThis library provides few utility functions which enable you to invoke a function and ensure it continues to execute.\u003cbr\u003e\nIn case the function exists due to a crash or simply because it finished, the forever library will reinvoke it.\u003cbr\u003e\nThe forever function provides control over the amount of retries and time to wait between intervals via parameters or via callback for a more\nfine grained control.\u003cbr\u003e\nThe provided function is invoked as a forked process, so any crash is caught and when restarts, it will be started as a new process with a new state.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\n\n\u003c!-- example source start --\u003e\n```c\n#include \"forever.h\"\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cunistd.h\u003e\n\n\nvoid my_program(void *context)\n{\n  if (context != NULL)\n  {\n    // do something with the context\n  }\n\n  sleep(1);\n  exit(0);\n}\n\n\nint callback(void *context, const unsigned char started, int stat_loc)\n{\n  if (context != NULL)\n  {\n    // do something with the context\n  }\n\n  if (stat_loc == 0 || !started)\n  {\n    return(-1); // no more retries\n  }\n\n  return(500); // wait 500 millies before next invocation, 0 for no wait.\n}\n\n\nint main()\n{\n  void *context = NULL;\n\n  // call 'my_program' and when it ends/crashes invoke it again, up\n  // to 10 times and wait 250 millies between invocations.\n  // counter will hold the amount of times 'my_program' was invoked.\n  unsigned int counter = forever_with_options(\n    my_program, // function to invoke\n    context,    // context that is passed to the function on every invocation\n    10,         // max amount of retries. 0 for unlimited retries.\n    250         // amount of millies to wait between invocations. 0 for no wait.\n    );\n\n  printf(\"Invoked %u time/s.\\n\", counter);\n\n  // call 'my_program' and when it ends/crashes call the provided callback\n  counter = forever_with_callback(my_program, context, callback);\n  printf(\"Invoked %u time/s.\\n\", counter);\n\n  // run with unlimited retries and no delay between invocations\n  forever(my_program, context);\n}\n```\n\u003c!-- example source end --\u003e\n\n## Contributing\nSee [contributing guide](.github/CONTRIBUTING.md)\n\n\u003ca name=\"history\"\u003e\u003c/a\u003e\n## Release History\n\nSee [Changelog](CHANGELOG.md)\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\nDeveloped by Sagie Gur-Ari and licensed under the Apache 2 open source license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Fc_forever","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagiegurari%2Fc_forever","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Fc_forever/lists"}