BSD is a family of Unix-like operating systems, including FreeBSD, NetBSD and OpenBSD.
Questions tagged [bsd]
510 questions
9
votes
2 answers
sed use: expected context address
I use the sed command on macOS with the following text:
$ cat pets.txt
This is my cat
my cat's name is betty
This is your dog
your dog's name is frank
This is your fish
your fish's name is george
This is my goat
my goat's name is adam
When…

lutaoact
- 4,149
- 6
- 29
- 41
9
votes
1 answer
Is it possible that `fileno(stdout) != 1` on a POSIX system?
Can stdout file descriptor differ from 1 (STDOUT_FILENO) assuming stdout need not be a modifiable lvalue?
For example, can freopen("/dev/null", "w", stdout) change fileno(stdout) result?

jfs
- 399,953
- 195
- 994
- 1,670
9
votes
1 answer
Non-greedy matching with grep
Non greedy matching as far as I know is not part of Basic Regular Expression (BRE) and Extended Regular Expression (ERE). However, the behaviour on different versions of grep (BSD and GNU) seems to suggest other wise.
For example, let's take the…

jaypal singh
- 74,723
- 23
- 102
- 147
9
votes
2 answers
Not checking close()'s return value: how serious, really?
Linux's "man close" warns (SVr4, 4.3BSD, POSIX.1-2001):
Not checking the return value of close() is a common but nevertheless serious programming error. It is quite possible that errors on a previous write(2) operation are first reported at the…

Camille Goudeseune
- 2,934
- 2
- 35
- 56
9
votes
1 answer
grep -f on OS X produces segfault
If you've got a Mac, try this:
echo 'abcd*' > grepfile
echo 'abc$' >> grepfile
echo '^abc' >> grepfile
echo "fojeiwuroiuwet\nljfajsljkfabcdddjlfkajlkj\nabcaaa\nzzzabc\n" | grep -f grepfile
Here's the version:
$ grep --v
grep (BSD grep)…

Steven Lu
- 41,389
- 58
- 210
- 364
8
votes
5 answers
Determine OS during runtime
Neither ISO C nor POSIX offer functionality to determine the underlying OS during runtime. From a theoretical point of view, it doesn't matter since C offers wrappers for the most common system calls, and from a nit-picking point of view, there…

Philip
- 5,795
- 3
- 33
- 68
8
votes
3 answers
Using select() for non-blocking sockets
I am trying to use the select function to have non-blocking i/o between a server and 1 client (no more) where the communication flows nicely (can send at any time and the other will receive without waiting to send). I found a tutorial with some code…

Sterling
- 3,835
- 14
- 48
- 73
8
votes
3 answers
What's the expected behavior of open(name, O_CREAT|O_DIRECTORY, mode)?
Despite a careful read of the related standard documentation, I can't understand what's the expected behavior in POSIX compliant systems when a open system call is invoked with flags including O_CREAT|O_DIRECTORY.
The standard specifies that
If…

Giacomo Tesio
- 7,144
- 3
- 31
- 48
8
votes
3 answers
How to turn a regular file into a symlink on Linux
I'm writing an (un)archiving tool and the way it is designed it first creates a regular file from the archive before it examines the special attributes and may decide that this item is a symlink, in fact.
Note: Before more people misunderstand me…

Thomas Tempelmann
- 11,045
- 8
- 74
- 149
8
votes
1 answer
How to iterate all mounted file systems on OSX
I am interested in iterating all mounted file systems on OSX (currently running 10.9 Mavericks). I am looking for something similar to getmntent() or the output of the mount shell command (although I want to do it from objective C, so parsing the…

John Bowers
- 1,695
- 1
- 16
- 26
8
votes
2 answers
Why does the doubly linked list in sys/queue.h maintain the address of previous next element?
I'm studying sys/queue.h from FreeBSD and I have one question:
In sys/queue.h, LIST_ENTRY is defined as follows:
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element…

Yanzhe Chen
- 427
- 3
- 9
8
votes
0 answers
PF packet filter: How do anchors with asterisk work?
I'm currently learning the pf packet filter installed on my Macbook (OS X Mountain Lion).
One thing I cannot get my head around are anchors or, more specifically, a certain feature concerning anchors. You can write anchors in the form of anchor…

j0ker
- 4,069
- 4
- 43
- 65
8
votes
3 answers
Non-blocking access to the file system
When writing a non-blocking program (handling multiple sockets) which at a certain point needs to open files using open(2), stat(2) files or open directories using opendir(2), how can I ensure that the system calls do not block?
To me it seems that…

watain
- 4,838
- 4
- 34
- 35
8
votes
3 answers
Why would `killpg` return “not permitted” when ownership is correct?
I've got some code which fork()s, calls setsid() in the child, and starts some processing. If any of the children quit (waitpid(-1, 0)), I kill all the child process groups:
child_pids = []
for child_func in child_functions:
pid = fork()
if…

David Wolever
- 148,955
- 89
- 346
- 502
8
votes
1 answer
Binutils stat illegal option -c
I use stat two times in my script once to find the file files permissions and once to find the size of the file.
`stat -c %A "$directory/$file"`
`stat -c %s "$directory/$file"`
I am using OSX 10.7 and directory and file are variable of the…

Joe Tyman
- 1,417
- 5
- 28
- 57