Questions tagged [posix]

POSIX (Portable Operating System Interface) is a set of standards defining programming APIs, a command interpreter, and common utilities for Unix-like operating systems.

POSIX (an acronym for "Portable Operating System Interface") is a family of standards that specifies the behaviour of Unix-like operating systems.

These standards define:

  • A standard operating system interface and environment
  • A programming API for the C programming language
  • The behavior of a command interpreter (or "shell")
  • The behavior of common utility programs invocable from the shell

The POSIX standards are developed by the Austin Common Standards Revision Group, a joint technical working group led by representatives from IEEE PASC, ISO/IEC JTC 1/SC 22, and The Open Group.

The current set of POSIX standards is available online.

POSIX is a trademark of the IEEE.

5973 questions
28
votes
4 answers

delete all directories except one

So using the shell, and having a directory: ./parent ./parent/one ./parent/two ./parent/three ./parent/four i want to do something like rm -rf parent/* in one command, but keeping one directory, for example 'four', so the end result would…
André Alçada Padez
  • 10,987
  • 24
  • 67
  • 120
28
votes
3 answers

Posix shared memory vs mapped files

Having learnt a bit about the subject, can anyone tell, what is the real difference between POSIX shared memory (shm_open) and POSIX mapped files (mmap)? Both seems to use the /dev/tmpfs subsystem, rather then older IPC mechanism. So is there any…
SyBer
  • 5,407
  • 13
  • 55
  • 64
28
votes
1 answer

How to check if the OS is POSIX compliant

I am writing a cross-platform application that creates temporary files and copies these to another location, where they need to be readable by everyone. (By default, only the owner has read access to temporary files.) I tried using the POSIX file…
Mangara
  • 1,116
  • 1
  • 10
  • 23
28
votes
4 answers

Setting thread priority in Linux with Boost

The Boost Libraries don't seem to have a device for setting a thread's priority. Would this be the best code to use on Linux or is there a better method? boost::thread myThread( MyFunction() ); struct sched_param param; param.sched_priority =…
SlickMcRunFast
  • 293
  • 1
  • 3
  • 9
28
votes
5 answers

Is there a minimally POSIX.2 compliant shell?

Is there a minimally POSIX.2 compliant shell (let's call it mpcsh) in the following sense: if mpcsh myscript.sh behaves correctly on my (compliant) system then xsh myscript.sh will behave identically for any POSIX.2 compliant shell xsh on any…
Hans Lub
  • 5,513
  • 1
  • 23
  • 43
27
votes
6 answers

How to delete a directory and its contents in (POSIX) C?

I am most interested in the non-recursive case, but I am guessing others who might track this question would prefer seeing the recursive case. Basically, we are aiming to accomplish: rm -rf However, a system call would be an immature…
Setjmp
  • 27,279
  • 27
  • 74
  • 92
27
votes
4 answers

What does select(2) do if you close(2) a file descriptor in a separate thread?

What is the behavior of the select(2) function when a file descriptor it is watching for reading is closed by another thread? From some cursory testing, it does return right away. I suspect the outcome is either that (a) it still continues to wait…
Joe Shaw
  • 22,066
  • 16
  • 70
  • 92
27
votes
2 answers

Java Threads vs Pthreads

I was asked this question in an interview today. "When we create a thread with pthread_create() (POSIX Threads), the thread starts on its own. Why do we need to explicitly call start() in Java. What is the reason that Java doesnt start the thread…
Chander Shivdasani
  • 9,878
  • 20
  • 76
  • 107
27
votes
5 answers

Function overloading in C

Today, looking at the man page for open(), I've noticed this function is 'overloaded': int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); I didn't thought it's possible on C. What's the 'trick'…
Andrei Ciobanu
  • 12,500
  • 24
  • 85
  • 118
26
votes
7 answers

How do I tell what type my shell is

How can I tell what type my shell is? ie, whether it's traditional sh, bash, ksh, csh, zsh etc. Note that checking $SHELL or $0 won't work because $SHELL isn't set by all shells, so if you start in one shell and then start a different one you may…
DrHyde
  • 1,546
  • 1
  • 14
  • 14
26
votes
4 answers

Arrays in a POSIX compliant shell

According to this reference sheet on hyperpolyglot.org, the following syntax can be used to set an array. i=(1 2 3) But I get an error with dash which is the default for /bin/sh on Ubuntu and should be POSIX compliant. # Trying the syntax with dash…
zoom
  • 1,686
  • 2
  • 16
  • 27
26
votes
4 answers

multiple threads doing poll() or select() on a single socket or pipe

What do POSIX and other standards say about the situation where multiple threads are doing poll() or select() calls on a single socket or pipe handle at the same time? If any data arrives, does only one of the waiting threads get woken up or do all…
wilx
  • 17,697
  • 6
  • 59
  • 114
25
votes
2 answers

Does realloc keep the memory alignment of posix_memalign?

Aligned malloc is posix_memalign, that's OK, but what about the aligned realloc? Does realloc retain the alignment or how to assure that reallocated memory has the same alignment? Assume Linux and x86_64.
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
25
votes
5 answers

Remove file in C++ under UNIX

How do you guys typically delete files on Linux OS? I am thinking of using the unlink function call, but I wonder if you have a better idea, as the C++ standard has no mention of file deletion operation and it is system dependent.
Sasha
25
votes
3 answers

How to mark an array in POSIX sh?

While replacing external commands in a shell script, I used an array to get rid of awk's NF. Now, since I moved from bash to POSIX sh, I cannot get the array marked right: #!/bin/bash export RANGE="0 1 4 6 8 16 24 46 53" RANGE=($RANGE) echo…
Charles
  • 251
  • 1
  • 3
  • 3