Linux

Centralised logging and monitoring server

Philosophical ramblings Why? Two reasons, network administration and security. From an administrative POV the server should be reliable, placed on a central point on the network, able to directly reach as many of the monitored items as possible so that the exact point of failure can be easily determined. It can’t do much monitoring if it’s not working due to hardware problems and by making it reach as many things as possible in as few hops...

Read More

C – fork a child process using vfork()

Creates a child process using vfork(). The child increments a global variable (glob) and a local one (var) and returns the corresponding process id of the respective process. With vfork() the child uses the same environment as the parent, so if the child changes these values, the parent uses the changed ones too.  /* creates a child process using vfork(). * the child increments a global variable (glob) * and a local one (var) and...

Read More

C – forking a child process using fork()

Creates a child process using fork(). The child increments a global variable (glob) and a local one (var) and returns the corresponding process id of each process. With fork() the child DOES NOT USE the same variables as the parent, so if the child changes these values, the parent still keeps his./* creates a child process using fork(). the child increments a global variable (glob) * and a local one (var) and returns the corresponding...

Read More

C – file type

Takes one or more files as arguments on the command line and returns the type of the file(s) (normal file, directory, etc.)/* reports the type of a file or of multiple files * that are given as arguments on the command line * it works too */ #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> int main (int argc, char *argv[]) /* In ISO C you can define `main’ either to take no arguments, or to *...

Read More

C – cut file to zero length

Modify a file without changing it’s access and modification times. This is old code, all this was done in school, many years ago, no idea if it still works on modern systems./* should open a file, truncate it to length 0 but keep the old acces and modification time */#include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<utime.h> #include<stdio.h> int main(int argc, char *argv[]) /* In ISO...

Read More

C – echo server

According to the comments this is supposed to be a very basic echo server. It was written for school many years ago and I didn’t turn out to be a C coder after all, though I remember this being fun, so for anyone stumbling upon this: DISCLAIMER – apparently it was six in the morning and looks like I was a bit drunk too, so, seriously, don’t try it if you don’t know what it does. You shouldn’t run unknown code on your system, specially...

Read More