pass arguments to running C app

I am writing small C program which will act like daemon and do something every second. I managed it to run only single instance using filelock and last thing I need to know is if it is possible to send commandline arguments to running program, something like that:

first program start:


then decide to take some action/update setting

./sampleprogram -r

it will be another rotation script for my thinkpad X41 convertible:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
/*#include <stdbool.h>*/
#define TRUE 1
#define FALSE 0
#define NIL -1

int fdlock;
int get_lock(void)
    struct flock fl;
    fl.l_type = F_WRLCK;
    fl.l_whence = SEEK_SET;
    fl.l_start = 0;
    fl.l_len = 1;
    if((fdlock = open("oneproc.lock", O_WRONLY|O_CREAT, 0666)) == -1) { return 0; }
    if(fcntl(fdlock, F_SETLK, &fl) == -1) { return 0; }
    return 1;

int main() {

    if(!get_lock()) {
        fputs("Process already running!\n", stderr);
        return 1;

    int tabletmode;
    int autorotate = TRUE;
    int prevmode = NIL;
    FILE *fstate;
    char state[1];
    FILE *fgyrovals;
    char gyroval_a[1];

    while (TRUE) {
        fstate = fopen("/sys/devices/platform/thinkpad_acpi/hotkey_tablet_mode", "r");
        fread(state, sizeof(state[0]), 1, fstate);
        /*tabletmode = atoi(state[0]);*/
        tabletmode = state[0] - '0';
        printf("koko: %d", tabletmode);

        if (prevmode != tabletmode) {
            if (tabletmode) {
                system("notify-send 'Notebook v tablet móde'");
            } else {
                system("notify-send 'Notebook v štandartnom režime'");

        if (tabletmode) {
            if (autorotate) {
                fgyrovals = fopen("/sys/devices/platform/hdaps/position", "r");

        prevmode = tabletmode;

    return 0;


Need Your Help

Debugging : is it possible to print all local variable (with values) of C code without going into each stack frame?

c debugging gdb coredump

I am trying to explore gdb, objdump, valgrind and nm tools for debugging purpose in linux.

Phonegap not detecting accurate location

html5 cordova geolocation

I am using HTML5 Geolocation API in phonegap to precisely detect my location. I am working from India I should ideally be able to see my location i.e. Pune, India but it doesn't do so.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.