Can user space programs provide/implement sysfs or procfs files to pass data to and from a program?
Kernel space device drivers usually implement directories and file that show through /sys
or /proc
. Can the long running user space programs do this as well?
I have a daemon or long running program that needs to be able to be queried for some data and have some data set by external programs while it runs.
I could do a full blown sockets interface, but that's a lot of overhead for the program and the external requestors.
As the linux kernel developers found, using the "everything is a file" model was useful for tweaking kernel setting. I'd like to do the same.
Some may think the /sys
directory is the sacred space of the kernel, but I don't see an important line between what is what is the "system" and some other services/servers/applications.
Using FUSE...
I've decided to use FUSE, the 'File system in USErspace' package libfuse3.so.
(After writing a wrapper for it...) I can define an array of structs, one per access variable/file:
struct fileObj files = {
{"mode", mode, getFunc, putFunc},
{"numbProcs", numbProcs, getFunc, putFunc},
{"svrHostPort", hostPort, getFunc, putFunc},
{"somethingWO", jakeBuf, NULL, putFunc}, // Write only file (why?)
{"timestamp", NULL, getTimestampFunc, NULL}, // Returns timestamp, R/O
{0}
};
The mountpoint for the FUSE filesystem is '/ssm/fuse'... The 'ls -l' shows that each entry in the 'files' array shows up as a file, some R/O, some R/W, one W/O. The 'getTimestampFunc in the 'get' function position shows that a special function can be associated with a file to perform calculate repsonses.
ribo@box:~/c$ ls -l /ssm/fuse
total 0
-rw-r--r-- 1 ribo ribo 10 Dec 28 17:17 mode
-rw-r--r-- 1 ribo ribo 1 Dec 28 17:17 numbProcs
--w------- 1 ribo ribo 3 Dec 28 17:17 somethingWO
-rw-r--r-- 1 ribo ribo 5 Dec 28 17:17 svrHostPort
-r--r--r-- 1 ribo ribo 32 Dec 28 17:17 timestamp
ribo@box:~/c$ cat /ssm/fuse/timestamp
18/12/28 17:17:27ribo@box:~/c$cat /ssm/fuse/mode
hyperSpeedribo@box:~/c$ echo slow >/ssm/fuse/mode
ribo@box:~/c$ cat /ssm/fuse/mode
slow
The 'echo >' shows passing a value into the program. So its easy for me to peek and poke various parameters of the program as it runs.
fuse sysfs procfs
add a comment |
Kernel space device drivers usually implement directories and file that show through /sys
or /proc
. Can the long running user space programs do this as well?
I have a daemon or long running program that needs to be able to be queried for some data and have some data set by external programs while it runs.
I could do a full blown sockets interface, but that's a lot of overhead for the program and the external requestors.
As the linux kernel developers found, using the "everything is a file" model was useful for tweaking kernel setting. I'd like to do the same.
Some may think the /sys
directory is the sacred space of the kernel, but I don't see an important line between what is what is the "system" and some other services/servers/applications.
Using FUSE...
I've decided to use FUSE, the 'File system in USErspace' package libfuse3.so.
(After writing a wrapper for it...) I can define an array of structs, one per access variable/file:
struct fileObj files = {
{"mode", mode, getFunc, putFunc},
{"numbProcs", numbProcs, getFunc, putFunc},
{"svrHostPort", hostPort, getFunc, putFunc},
{"somethingWO", jakeBuf, NULL, putFunc}, // Write only file (why?)
{"timestamp", NULL, getTimestampFunc, NULL}, // Returns timestamp, R/O
{0}
};
The mountpoint for the FUSE filesystem is '/ssm/fuse'... The 'ls -l' shows that each entry in the 'files' array shows up as a file, some R/O, some R/W, one W/O. The 'getTimestampFunc in the 'get' function position shows that a special function can be associated with a file to perform calculate repsonses.
ribo@box:~/c$ ls -l /ssm/fuse
total 0
-rw-r--r-- 1 ribo ribo 10 Dec 28 17:17 mode
-rw-r--r-- 1 ribo ribo 1 Dec 28 17:17 numbProcs
--w------- 1 ribo ribo 3 Dec 28 17:17 somethingWO
-rw-r--r-- 1 ribo ribo 5 Dec 28 17:17 svrHostPort
-r--r--r-- 1 ribo ribo 32 Dec 28 17:17 timestamp
ribo@box:~/c$ cat /ssm/fuse/timestamp
18/12/28 17:17:27ribo@box:~/c$cat /ssm/fuse/mode
hyperSpeedribo@box:~/c$ echo slow >/ssm/fuse/mode
ribo@box:~/c$ cat /ssm/fuse/mode
slow
The 'echo >' shows passing a value into the program. So its easy for me to peek and poke various parameters of the program as it runs.
fuse sysfs procfs
add a comment |
Kernel space device drivers usually implement directories and file that show through /sys
or /proc
. Can the long running user space programs do this as well?
I have a daemon or long running program that needs to be able to be queried for some data and have some data set by external programs while it runs.
I could do a full blown sockets interface, but that's a lot of overhead for the program and the external requestors.
As the linux kernel developers found, using the "everything is a file" model was useful for tweaking kernel setting. I'd like to do the same.
Some may think the /sys
directory is the sacred space of the kernel, but I don't see an important line between what is what is the "system" and some other services/servers/applications.
Using FUSE...
I've decided to use FUSE, the 'File system in USErspace' package libfuse3.so.
(After writing a wrapper for it...) I can define an array of structs, one per access variable/file:
struct fileObj files = {
{"mode", mode, getFunc, putFunc},
{"numbProcs", numbProcs, getFunc, putFunc},
{"svrHostPort", hostPort, getFunc, putFunc},
{"somethingWO", jakeBuf, NULL, putFunc}, // Write only file (why?)
{"timestamp", NULL, getTimestampFunc, NULL}, // Returns timestamp, R/O
{0}
};
The mountpoint for the FUSE filesystem is '/ssm/fuse'... The 'ls -l' shows that each entry in the 'files' array shows up as a file, some R/O, some R/W, one W/O. The 'getTimestampFunc in the 'get' function position shows that a special function can be associated with a file to perform calculate repsonses.
ribo@box:~/c$ ls -l /ssm/fuse
total 0
-rw-r--r-- 1 ribo ribo 10 Dec 28 17:17 mode
-rw-r--r-- 1 ribo ribo 1 Dec 28 17:17 numbProcs
--w------- 1 ribo ribo 3 Dec 28 17:17 somethingWO
-rw-r--r-- 1 ribo ribo 5 Dec 28 17:17 svrHostPort
-r--r--r-- 1 ribo ribo 32 Dec 28 17:17 timestamp
ribo@box:~/c$ cat /ssm/fuse/timestamp
18/12/28 17:17:27ribo@box:~/c$cat /ssm/fuse/mode
hyperSpeedribo@box:~/c$ echo slow >/ssm/fuse/mode
ribo@box:~/c$ cat /ssm/fuse/mode
slow
The 'echo >' shows passing a value into the program. So its easy for me to peek and poke various parameters of the program as it runs.
fuse sysfs procfs
Kernel space device drivers usually implement directories and file that show through /sys
or /proc
. Can the long running user space programs do this as well?
I have a daemon or long running program that needs to be able to be queried for some data and have some data set by external programs while it runs.
I could do a full blown sockets interface, but that's a lot of overhead for the program and the external requestors.
As the linux kernel developers found, using the "everything is a file" model was useful for tweaking kernel setting. I'd like to do the same.
Some may think the /sys
directory is the sacred space of the kernel, but I don't see an important line between what is what is the "system" and some other services/servers/applications.
Using FUSE...
I've decided to use FUSE, the 'File system in USErspace' package libfuse3.so.
(After writing a wrapper for it...) I can define an array of structs, one per access variable/file:
struct fileObj files = {
{"mode", mode, getFunc, putFunc},
{"numbProcs", numbProcs, getFunc, putFunc},
{"svrHostPort", hostPort, getFunc, putFunc},
{"somethingWO", jakeBuf, NULL, putFunc}, // Write only file (why?)
{"timestamp", NULL, getTimestampFunc, NULL}, // Returns timestamp, R/O
{0}
};
The mountpoint for the FUSE filesystem is '/ssm/fuse'... The 'ls -l' shows that each entry in the 'files' array shows up as a file, some R/O, some R/W, one W/O. The 'getTimestampFunc in the 'get' function position shows that a special function can be associated with a file to perform calculate repsonses.
ribo@box:~/c$ ls -l /ssm/fuse
total 0
-rw-r--r-- 1 ribo ribo 10 Dec 28 17:17 mode
-rw-r--r-- 1 ribo ribo 1 Dec 28 17:17 numbProcs
--w------- 1 ribo ribo 3 Dec 28 17:17 somethingWO
-rw-r--r-- 1 ribo ribo 5 Dec 28 17:17 svrHostPort
-r--r--r-- 1 ribo ribo 32 Dec 28 17:17 timestamp
ribo@box:~/c$ cat /ssm/fuse/timestamp
18/12/28 17:17:27ribo@box:~/c$cat /ssm/fuse/mode
hyperSpeedribo@box:~/c$ echo slow >/ssm/fuse/mode
ribo@box:~/c$ cat /ssm/fuse/mode
slow
The 'echo >' shows passing a value into the program. So its easy for me to peek and poke various parameters of the program as it runs.
fuse sysfs procfs
fuse sysfs procfs
edited 1 hour ago
asked yesterday
Ribo
1176
1176
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I don’t think there’s any way to add /sys
or /proc
entries outside the kernel. For /sys
it wouldn’t make much sense anyway — it’s a direct representation of kobject data structures.
You can however provide similar interfaces from userspace, for example using FIFOs; see mkfifo
for details. You can see an implementation of this in sysvinit
with its initctl
FIFO.
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
add a comment |
Surely they can. You can mount anything (actual disk filesystems, fuse filesystems, bind mounts) below /sys
or /proc
.
Whether that's a good idea, it's a completely different matter.
Example:
# unshare -m
# touch /tmp/foo
# mount -B /tmp/foo /proc/1/status
# echo FOR GREAT JUSTICE > /proc/1/status
# cat /proc/1/status
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491140%2fcan-user-space-programs-provide-implement-sysfs-or-procfs-files-to-pass-data-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don’t think there’s any way to add /sys
or /proc
entries outside the kernel. For /sys
it wouldn’t make much sense anyway — it’s a direct representation of kobject data structures.
You can however provide similar interfaces from userspace, for example using FIFOs; see mkfifo
for details. You can see an implementation of this in sysvinit
with its initctl
FIFO.
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
add a comment |
I don’t think there’s any way to add /sys
or /proc
entries outside the kernel. For /sys
it wouldn’t make much sense anyway — it’s a direct representation of kobject data structures.
You can however provide similar interfaces from userspace, for example using FIFOs; see mkfifo
for details. You can see an implementation of this in sysvinit
with its initctl
FIFO.
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
add a comment |
I don’t think there’s any way to add /sys
or /proc
entries outside the kernel. For /sys
it wouldn’t make much sense anyway — it’s a direct representation of kobject data structures.
You can however provide similar interfaces from userspace, for example using FIFOs; see mkfifo
for details. You can see an implementation of this in sysvinit
with its initctl
FIFO.
I don’t think there’s any way to add /sys
or /proc
entries outside the kernel. For /sys
it wouldn’t make much sense anyway — it’s a direct representation of kobject data structures.
You can however provide similar interfaces from userspace, for example using FIFOs; see mkfifo
for details. You can see an implementation of this in sysvinit
with its initctl
FIFO.
answered yesterday
Stephen Kitt
163k24365444
163k24365444
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
add a comment |
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
Yes, mkfifo files are sort of like a socket, and could be used, but there is a lot of work for the daemon/long running program to have a thread to wait for incoming data and parse the request. I liked the callbacks you get in fuse-like virtual file systems, and the file system model provides sorting out different requests (ie different file names would be for different values)
– Ribo
yesterday
add a comment |
Surely they can. You can mount anything (actual disk filesystems, fuse filesystems, bind mounts) below /sys
or /proc
.
Whether that's a good idea, it's a completely different matter.
Example:
# unshare -m
# touch /tmp/foo
# mount -B /tmp/foo /proc/1/status
# echo FOR GREAT JUSTICE > /proc/1/status
# cat /proc/1/status
add a comment |
Surely they can. You can mount anything (actual disk filesystems, fuse filesystems, bind mounts) below /sys
or /proc
.
Whether that's a good idea, it's a completely different matter.
Example:
# unshare -m
# touch /tmp/foo
# mount -B /tmp/foo /proc/1/status
# echo FOR GREAT JUSTICE > /proc/1/status
# cat /proc/1/status
add a comment |
Surely they can. You can mount anything (actual disk filesystems, fuse filesystems, bind mounts) below /sys
or /proc
.
Whether that's a good idea, it's a completely different matter.
Example:
# unshare -m
# touch /tmp/foo
# mount -B /tmp/foo /proc/1/status
# echo FOR GREAT JUSTICE > /proc/1/status
# cat /proc/1/status
Surely they can. You can mount anything (actual disk filesystems, fuse filesystems, bind mounts) below /sys
or /proc
.
Whether that's a good idea, it's a completely different matter.
Example:
# unshare -m
# touch /tmp/foo
# mount -B /tmp/foo /proc/1/status
# echo FOR GREAT JUSTICE > /proc/1/status
# cat /proc/1/status
answered yesterday
mosvy
5,8401325
5,8401325
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491140%2fcan-user-space-programs-provide-implement-sysfs-or-procfs-files-to-pass-data-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown