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
96
votes
3 answers

How to get a FILE pointer from a file descriptor?

I'm playing around with mkstemp(), which provides a file descriptor, but I want to generate formatted output via fprintf(). Is there an easy way to transform the file descriptor provided by mkstemp() into a FILE * structure that is suitable for use…
BD at Rivenhill
  • 12,395
  • 10
  • 46
  • 49
92
votes
6 answers

Can argc be zero on a POSIX system?

Given the standard definition for the main program: int main(int argc, char *argv[]) { ... } Under which circumstances can argc be zero on a POSIX system?
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
92
votes
3 answers

How to get script directory in POSIX sh?

I have the following code in my bash script. Now I wanna use it in POSIX sh. How can I convert it? DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
city
  • 2,036
  • 2
  • 32
  • 40
90
votes
5 answers

What does EAGAIN mean?

As in the title what does EAGAIN mean?
David van Dugteren
  • 3,879
  • 9
  • 33
  • 48
90
votes
4 answers

How to make parent wait for all child processes to finish?

I'm hoping someone could shed some light on how to make the parent wait for ALL child processes to finish before continuing after the fork. I have cleanup code which I want to run but the child processes need to have returned before this can…
Donatello
  • 947
  • 1
  • 7
  • 6
89
votes
3 answers

Difference between C standard library and C POSIX library

I'm a little confused by "C standard lib" and "C POSIX lib", because I found that, many header files defined in "C POSIX lib" are also part of "C standard lib". So, I assume that, "C standard lib" is a lib defined by ANSI C organization, and there…
Alcott
  • 17,905
  • 32
  • 116
  • 173
87
votes
7 answers

How to use nanosleep() in C? What are `tim.tv_sec` and `tim.tv_nsec`?

What is the use of tim.tv_sec and tim.tv_nsec in the following? How can I sleep execution for 500000 microseconds? #include #include int main() { struct timespec tim, tim2; tim.tv_sec = 1; tim.tv_nsec = 500; …
pnizzle
  • 6,243
  • 4
  • 52
  • 81
85
votes
3 answers

What can lead to "IOError: [Errno 9] Bad file descriptor" during os.system()?

I am using a scientific software including a Python script that is calling os.system() which is used to run another scientific program. While the subprocess is running, Python at some point prints the following: close failed in file object…
Dr. Jan-Philip Gehrcke
  • 33,287
  • 14
  • 85
  • 130
85
votes
5 answers

Is Mac OS X a POSIX OS?

What is it that makes an OS a POSIX system? All versions of Linux are POSIX, right? What about Mac OS X?
node ninja
  • 31,796
  • 59
  • 166
  • 254
85
votes
8 answers

Is an atomic file rename (with overwrite) possible on Windows?

On POSIX systems rename(2) provides for an atomic rename operation, including overwriting of the destination file if it exists and if permissions allow. Is there any way to get the same semantics on Windows? I know about MoveFileTransacted() on…
teratorn
  • 1,489
  • 1
  • 11
  • 12
81
votes
2 answers

Test for empty string with X""

I know I can test for an empty string in Bash with -z like so: if [[ -z $myvar ]]; then do_stuff; fi but I see a lot of code written like: if [[ X"" = X"$myvar" ]]; then do_stuff; fi Is that method more portable? Is it just historical cruft from…
mgalgs
  • 15,671
  • 11
  • 61
  • 74
80
votes
16 answers

Recursive mkdir() system call on Unix

After reading the mkdir(2) man page for the Unix system call with that name, it appears that the call doesn't create intermediate directories in a path, only the last directory in the path. Is there any way (or other function) to create all the…
Alex Marshall
  • 10,162
  • 15
  • 72
  • 117
79
votes
5 answers

Are message queues obsolete in linux?

I've been playing with message queues (System V, but POSIX should be ok too) in Linux recently and they seem perfect for my application, but after reading The Art of Unix Programming I'm not sure if they are really a good…
Purple Tentacle
  • 1,606
  • 1
  • 17
  • 19
79
votes
10 answers

Can I assume the size of long int is always 4 bytes?

Is it always true that long int (which as far as I understand is a synonym for long) is 4 bytes? Can I rely on that? If not, could it be true for a POSIX based OS?
Elimination
  • 2,619
  • 4
  • 22
  • 38
79
votes
5 answers

Kill all processes for a given user

Is there a reliable way to kill all the processes of a given user? kill(-1, SIGKILL) as that user will work, unless a rogue process of that user kills the killing process first. The best I can find so far is to loop through system("ps -u") for that…
Shea Levy
  • 5,237
  • 3
  • 31
  • 42