Skip to contentSkip to conversation

Show application performance/errors from pseudo file

DISCUSSION Daniel Hilst Selli 3 participants 6 messages Oct 16, 2014 – Oct 23, 2014 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

I'm writing a new application and would be nice to have a pseudo file showing its status, just the way that procfs does with kernel. I'm looking for sugestions, I want to `cat' files contents and have something similar to /proc/meminfo

First I think using named pipes, but, AFAIK, pipes would retain data writed until someone read it, what I thought is a kind of read hook that only show data when asked for. Here are a few requisites,

- Don't retain data
- Don't generate disk I/O
- Vanish when application stops
- Work with a simple cat or something similar..

With that in mind I think about using unix domain sockets.. it seems to fit all requisites, for the fourth requisite I could use netcat, that is almost cat,

Cheers

#1 lore raw

I’m no expert but I believe you’d need a kernel module to create the char device, then have your application talk to it somehow?
http://stackoverflow.com/questions/5970595/create-a-device-node-in-code

Quoted 11 lines · Daniel Hilst Selli

I'm writing a new application and would be nice to have a pseudo file showing its status, just the way that procfs does with kernel. I'm looking for sugestions, I want to `cat' files contents and have something similar to /proc/meminfo

First I think using named pipes, but, AFAIK, pipes would retain data writed until someone read it, what I thought is a kind of read hook that only show data when asked for. Here are a few requisites,

- Don't retain data
- Don't generate disk I/O
- Vanish when application stops
- Work with a simple cat or something similar..

Quoted 8 lines

With that in mind I think about using unix domain sockets.. it seems to fit all requisites, for the fourth requisite I could use netcat, that is almost cat,

Cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CAMvDr+T54gR3APzCOyZczvCTZs=FvHhsCA0VkZAVJR3BQdeT+w@mail.gmail.com

#3 lore raw

Resend as plain text.

Quoted 38 lines · Yichao Yu
Quoted 6 lines · Daniel Hilst Selli

I'm writing a new application and would be nice to have a pseudo file showing its status, just the way that procfs does with kernel. I'm looking for sugestions, I want to `cat' files contents and have something similar to /proc/meminfo

Quoted 8 lines

First I think using named pipes, but, AFAIK, pipes would retain data writed until someone read it, what I thought is a kind of read hook that only show data when asked for. Here are a few requisites,

- Don't retain data
- Don't generate disk I/O
- Vanish when application stops
- Work with a simple cat or something similar..

You should have a look at fuse[1].

[1] http://fuse.sourceforge.net/

Quoted 12 lines

With that in mind I think about using unix domain sockets.. it seems to fit all requisites, for
the fourth requisite I could use netcat, that is almost cat,

Cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 41 lines · Yichao Yu

Resend as plain text.

Quoted 38 lines · Yichao Yu
Quoted 6 lines · Daniel Hilst Selli

I'm writing a new application and would be nice to have a pseudo file showing its status, just the way that procfs does with kernel. I'm looking for sugestions, I want to `cat' files contents and have something similar to /proc/meminfo

Quoted 8 lines

First I think using named pipes, but, AFAIK, pipes would retain data writed until someone read it, what I thought is a kind of read hook that only show data when asked for. Here are a few requisites,

- Don't retain data
- Don't generate disk I/O
- Vanish when application stops
- Work with a simple cat or something similar..

You should have a look at fuse[1].

[1] http://fuse.sourceforge.net/

Quoted 12 lines

With that in mind I think about using unix domain sockets.. it seems to fit all requisites, for
the fourth requisite I could use netcat, that is almost cat,

Cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Seems god, a little overkill for so simple stuff but adds nice features, I'm taking a look on further options..

Cheers

#5 lore raw
Quoted 43 lines · Daniel Hilst Selli
Quoted 41 lines · Yichao Yu

Resend as plain text.

Quoted 38 lines · Yichao Yu
Quoted 6 lines · Daniel Hilst Selli

I'm writing a new application and would be nice to have a pseudo file showing its status, just the way that procfs does with kernel. I'm looking for sugestions, I want to `cat' files contents and have something similar to /proc/meminfo

Quoted 8 lines

First I think using named pipes, but, AFAIK, pipes would retain data writed until someone read it, what I thought is a kind of read hook that only show data when asked for. Here are a few requisites,

- Don't retain data
- Don't generate disk I/O
- Vanish when application stops
- Work with a simple cat or something similar..

You should have a look at fuse[1].

[1] http://fuse.sourceforge.net/

Quoted 12 lines

With that in mind I think about using unix domain sockets.. it seems to fit all requisites, for
the fourth requisite I could use netcat, that is almost cat,

Cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 4 lines

Seems god, a little overkill for so simple stuff but adds nice features, I'm taking a look on further options..

Cheers

good*

#6 lore raw
Quoted 44 lines · Daniel Hilst Selli
Quoted 43 lines · Daniel Hilst Selli
Quoted 41 lines · Yichao Yu

Resend as plain text.

Quoted 38 lines · Yichao Yu
Quoted 6 lines · Daniel Hilst Selli

I'm writing a new application and would be nice to have a pseudo file showing its status, just the way that procfs does with kernel. I'm looking for sugestions, I want to `cat' files contents and have something similar to /proc/meminfo

Quoted 8 lines

First I think using named pipes, but, AFAIK, pipes would retain data writed until someone read it, what I thought is a kind of read hook that only show data when asked for. Here are a few requisites,

- Don't retain data
- Don't generate disk I/O
- Vanish when application stops
- Work with a simple cat or something similar..

You should have a look at fuse[1].

[1] http://fuse.sourceforge.net/

Quoted 12 lines

With that in mind I think about using unix domain sockets.. it seems to fit all requisites, for
the fourth requisite I could use netcat, that is almost cat,

Cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 5 lines
Quoted 4 lines

Seems god, a little overkill for so simple stuff but adds nice features, I'm taking a look on further options..

Cheers

good*

Looking further I found that named pipes will block on open() calls, until the other end open it too. So I still can implement this with named pipes.

Here is the pseudo code implementation I use. (Yes I'm using threads)

void *stats_handler(void *unused)

{
	for (;;) {
		int fd = open(FIFO_PATH, O_WRONLY); /* should block here */

                /* handle open error */

		write(fd, statistics_buffer, statistics_buffer_len);

		close(fd);

		sleep(1); /* avoid flooders :-P */
	}
}

void stats_init(void)

{
	pthread_t stat_id;

	mkfifo(FIFO_PATH, 0755);
	/* handle mkfifo errors */
	pthread_create(&stat_id, NULL, stats_handler, NULL);
}

int main(void)

{
	...
	stats_init();
	...
}

After that I can just `cat FIFO_PATH' to see my statistics :D

Thanks for all and best regards!