Shell program to just open a character driver and wait
up vote
5
down vote
favorite
What inspired this question is that I am testing the functionality of watchdog device and I was thinking if there is a shell inbuilt command to just open the device and do nothing/wait until terminated?
Echo/touch
seem to just open and close the device immediately after performing the operation. Cat
does not seem to work.
I am using a C application to do the same but was wondering if shell script has some provision for it
linux bash shell-script
add a comment |
up vote
5
down vote
favorite
What inspired this question is that I am testing the functionality of watchdog device and I was thinking if there is a shell inbuilt command to just open the device and do nothing/wait until terminated?
Echo/touch
seem to just open and close the device immediately after performing the operation. Cat
does not seem to work.
I am using a C application to do the same but was wondering if shell script has some provision for it
linux bash shell-script
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
What inspired this question is that I am testing the functionality of watchdog device and I was thinking if there is a shell inbuilt command to just open the device and do nothing/wait until terminated?
Echo/touch
seem to just open and close the device immediately after performing the operation. Cat
does not seem to work.
I am using a C application to do the same but was wondering if shell script has some provision for it
linux bash shell-script
What inspired this question is that I am testing the functionality of watchdog device and I was thinking if there is a shell inbuilt command to just open the device and do nothing/wait until terminated?
Echo/touch
seem to just open and close the device immediately after performing the operation. Cat
does not seem to work.
I am using a C application to do the same but was wondering if shell script has some provision for it
linux bash shell-script
linux bash shell-script
asked yesterday
yashC
557
557
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
11
down vote
accepted
In Bourne-like shells,
exec 3< "$device"
Opens the device on file descriptor 3 of the shell.
That would be more or less equivalent to C's:
fd = open(device, O_RDONLY);
if (fd < 0) handler_error(...);
if (fd != 3) { dup2(fd, 3); close(fd); }
(ksh93
also does a fcntl(3, F_SETFD, FD_CLOEXEC)
on that fd).
To close it: exec 3<&-
In zsh
, ksh93
and bash
, the equivalent of fd = open(device, O_RDONLY)
could also be written as:
exec {fd}< "$device"
Where the file descriptor would be the first free one above 9 and stored in $fd
.
To close it: exec {fd}<&-
Replace <
with >
for O_WRONLY|O_CREAT|O_TRUNC
, and with <>
for O_RDWR|O_CREAT
and >>
for O_WRONLY|O_CREAT|O_APPEND
.
zsh
also has a sysopen
builtin (in the zsh/system
module) where you can specify the flags exactly.
Note that in POSIX compliant shells, exec
being a special builtin, if the file can't be opened, it's a fatal error when non-interactive (it exits the script). You can disabled that by using the command
command.
if command exec 3< "$device"; then
do-what-you-need-to-do
else
handle-the-error-yourself
fi
add a comment |
up vote
2
down vote
while sleep 3600; do :; done >/dev/your_watchdog
I gather (from the echo
and touch
working and the cat
failing) that the device should be open in write only mode.
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...
– Digital Trauma
yesterday
sleep: invalid number '1e99'
;-)
– pizdelect
yesterday
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
accepted
In Bourne-like shells,
exec 3< "$device"
Opens the device on file descriptor 3 of the shell.
That would be more or less equivalent to C's:
fd = open(device, O_RDONLY);
if (fd < 0) handler_error(...);
if (fd != 3) { dup2(fd, 3); close(fd); }
(ksh93
also does a fcntl(3, F_SETFD, FD_CLOEXEC)
on that fd).
To close it: exec 3<&-
In zsh
, ksh93
and bash
, the equivalent of fd = open(device, O_RDONLY)
could also be written as:
exec {fd}< "$device"
Where the file descriptor would be the first free one above 9 and stored in $fd
.
To close it: exec {fd}<&-
Replace <
with >
for O_WRONLY|O_CREAT|O_TRUNC
, and with <>
for O_RDWR|O_CREAT
and >>
for O_WRONLY|O_CREAT|O_APPEND
.
zsh
also has a sysopen
builtin (in the zsh/system
module) where you can specify the flags exactly.
Note that in POSIX compliant shells, exec
being a special builtin, if the file can't be opened, it's a fatal error when non-interactive (it exits the script). You can disabled that by using the command
command.
if command exec 3< "$device"; then
do-what-you-need-to-do
else
handle-the-error-yourself
fi
add a comment |
up vote
11
down vote
accepted
In Bourne-like shells,
exec 3< "$device"
Opens the device on file descriptor 3 of the shell.
That would be more or less equivalent to C's:
fd = open(device, O_RDONLY);
if (fd < 0) handler_error(...);
if (fd != 3) { dup2(fd, 3); close(fd); }
(ksh93
also does a fcntl(3, F_SETFD, FD_CLOEXEC)
on that fd).
To close it: exec 3<&-
In zsh
, ksh93
and bash
, the equivalent of fd = open(device, O_RDONLY)
could also be written as:
exec {fd}< "$device"
Where the file descriptor would be the first free one above 9 and stored in $fd
.
To close it: exec {fd}<&-
Replace <
with >
for O_WRONLY|O_CREAT|O_TRUNC
, and with <>
for O_RDWR|O_CREAT
and >>
for O_WRONLY|O_CREAT|O_APPEND
.
zsh
also has a sysopen
builtin (in the zsh/system
module) where you can specify the flags exactly.
Note that in POSIX compliant shells, exec
being a special builtin, if the file can't be opened, it's a fatal error when non-interactive (it exits the script). You can disabled that by using the command
command.
if command exec 3< "$device"; then
do-what-you-need-to-do
else
handle-the-error-yourself
fi
add a comment |
up vote
11
down vote
accepted
up vote
11
down vote
accepted
In Bourne-like shells,
exec 3< "$device"
Opens the device on file descriptor 3 of the shell.
That would be more or less equivalent to C's:
fd = open(device, O_RDONLY);
if (fd < 0) handler_error(...);
if (fd != 3) { dup2(fd, 3); close(fd); }
(ksh93
also does a fcntl(3, F_SETFD, FD_CLOEXEC)
on that fd).
To close it: exec 3<&-
In zsh
, ksh93
and bash
, the equivalent of fd = open(device, O_RDONLY)
could also be written as:
exec {fd}< "$device"
Where the file descriptor would be the first free one above 9 and stored in $fd
.
To close it: exec {fd}<&-
Replace <
with >
for O_WRONLY|O_CREAT|O_TRUNC
, and with <>
for O_RDWR|O_CREAT
and >>
for O_WRONLY|O_CREAT|O_APPEND
.
zsh
also has a sysopen
builtin (in the zsh/system
module) where you can specify the flags exactly.
Note that in POSIX compliant shells, exec
being a special builtin, if the file can't be opened, it's a fatal error when non-interactive (it exits the script). You can disabled that by using the command
command.
if command exec 3< "$device"; then
do-what-you-need-to-do
else
handle-the-error-yourself
fi
In Bourne-like shells,
exec 3< "$device"
Opens the device on file descriptor 3 of the shell.
That would be more or less equivalent to C's:
fd = open(device, O_RDONLY);
if (fd < 0) handler_error(...);
if (fd != 3) { dup2(fd, 3); close(fd); }
(ksh93
also does a fcntl(3, F_SETFD, FD_CLOEXEC)
on that fd).
To close it: exec 3<&-
In zsh
, ksh93
and bash
, the equivalent of fd = open(device, O_RDONLY)
could also be written as:
exec {fd}< "$device"
Where the file descriptor would be the first free one above 9 and stored in $fd
.
To close it: exec {fd}<&-
Replace <
with >
for O_WRONLY|O_CREAT|O_TRUNC
, and with <>
for O_RDWR|O_CREAT
and >>
for O_WRONLY|O_CREAT|O_APPEND
.
zsh
also has a sysopen
builtin (in the zsh/system
module) where you can specify the flags exactly.
Note that in POSIX compliant shells, exec
being a special builtin, if the file can't be opened, it's a fatal error when non-interactive (it exits the script). You can disabled that by using the command
command.
if command exec 3< "$device"; then
do-what-you-need-to-do
else
handle-the-error-yourself
fi
edited yesterday
answered yesterday
Stéphane Chazelas
297k54561907
297k54561907
add a comment |
add a comment |
up vote
2
down vote
while sleep 3600; do :; done >/dev/your_watchdog
I gather (from the echo
and touch
working and the cat
failing) that the device should be open in write only mode.
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...
– Digital Trauma
yesterday
sleep: invalid number '1e99'
;-)
– pizdelect
yesterday
add a comment |
up vote
2
down vote
while sleep 3600; do :; done >/dev/your_watchdog
I gather (from the echo
and touch
working and the cat
failing) that the device should be open in write only mode.
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...
– Digital Trauma
yesterday
sleep: invalid number '1e99'
;-)
– pizdelect
yesterday
add a comment |
up vote
2
down vote
up vote
2
down vote
while sleep 3600; do :; done >/dev/your_watchdog
I gather (from the echo
and touch
working and the cat
failing) that the device should be open in write only mode.
while sleep 3600; do :; done >/dev/your_watchdog
I gather (from the echo
and touch
working and the cat
failing) that the device should be open in write only mode.
answered yesterday
pizdelect
31815
31815
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...
– Digital Trauma
yesterday
sleep: invalid number '1e99'
;-)
– pizdelect
yesterday
add a comment |
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...
– Digital Trauma
yesterday
sleep: invalid number '1e99'
;-)
– pizdelect
yesterday
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...– Digital Trauma
yesterday
sleep 1e99 >/dev/your_watchdog
would also work, assuming you're not planning on being after 10 to the 91 years or so...– Digital Trauma
yesterday
sleep: invalid number '1e99'
;-)– pizdelect
yesterday
sleep: invalid number '1e99'
;-)– pizdelect
yesterday
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%2f487113%2fshell-program-to-just-open-a-character-driver-and-wait%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