[ Home | Dev | Build | Git | Bash | Py | Cpp | Gtk | Other ]
GCC cleanup attribute
Feature test macros
#define _GNU_SOURCE
error functions
#define APPNAME "appname"
static void error_exit(const char *msg)
{
if (!msg || *msg == '\0')
{
msg = "an error occurred";
}
printf("*** %s\nabort...\n", msg);
exit(EXIT_FAILURE);
}
static void usage_exit()
{
printf("*** usage :\n");
printf("%s param\n", APPNAME);
printf("abort...\n");
exit(EXIT_FAILURE);
}
args parsing
int n = 1;
while (n < argc)
{
if (strcmp(argv[n], "-opt") == 0)
{
return EXIT_SUCCESS;
}
else if (strcmp(argv[n], "-arg") == 0)
{
if (++n >= argc)
usage_exit();
return EXIT_SUCCESS;
}
else
{
usage_exit();
}
++n;
}
Reporting information using syslog
Current directory in C
https://stackoverflow.com/questions/298510/
#include <unistd.h>
char *getcwd(char *buf, size_t size);
Parse html using C
Execution time of C program
https://stackoverflow.com/questions/5248915/
https://stackoverflow.com/questions/55344890/
Clear the console
Polkit applications
https://www.freedesktop.org/software/polkit/docs/0.105/polkit-apps.html
string starts with
_vscprintf
stat, fstat, lstat
http://manpages.ubuntu.com/manpages/trusty/fr/man2/stat.2.html
open vs fopen
fgets
https://www.tutorialspoint.com/c_standard_library/c_function
https://koor.fr/C/cstdio/fgets.wp
CPU getusage_c
https://github.com/fho/code_snippets/blob/master/c/getusage.c
Audio playing detect
GKeyFile
Execute program in C
popen
posix_spawn
https://www.systutorials.com/a-posix_spawn-example-in-c-to-create-child-process-on-linux/
Exit status code
select
https://www.blaess.fr/christophe/2013/12/27/comprendre-le-fonctionnement-de-select/
Examples
https://gist.github.com/copyninja/1033862
https://www.thegeekstuff.com/2012/02/c-daemon-process/
https://www.google.com/search?channel=fs&client=ubuntu&q=daemon+example+in+c
http://netzmafia.de/skripten/unix/linux-daemon-howto.html
https://lloydrochester.com/post/c/unix-daemon-example/
https://github.com/pasce/daemon-skeleton-linux-c
https://gitlab.com/sulincix/fork/-/blob/master/src/pfork.c
Reading from a pipe
output of process in C
http://www.microhowto.info/howto/capture_the_output_of_a_child_process_in_c.html
Redirect pipe dup2
https://linuxfr.org/forums/programmation-c--2/posts/communication-entre-processus-avec-pipe-et-dup2
Redirect to buffer or file
QtCreator printf
https://chowdera.com/2020/12/20201208210320326z.html
setbuf(stdout, NULL);
QtCreator per-project tab spacing
https://forum.qt.io/topic/86319/qt-creator-how-to-do-per-pro
Memory usage of current process
RAM usage of a process using its ID