Hot answers tagged system-calls
16
About your performance question, pipes are more efficient than files because no disk IO is needed. So cmd1 | cmd2 is more efficient than cmd1 > tmpfile; cmd2 < tmpfile (this might not be true if tmpfile is backed on a RAM disk or other memory device as named pipe; but if it is a named pipe, cmd1 should be run in the background as its output can block ...
16
If it is in your path, then you can run either type git or which git. The which command has had problems getting the proper path (confusion between environment and dot files). For type, you can get just the path with the -p argument.
If it is not in your path, then it's best to look for it with locate -b git It will find anything named 'git'. It'll be a ...
11
Man pages are usually terse reference documents. Wikipedia is a better place to turn to for conceptual explanations.
Fork duplicates a process: it creates a child process which is almost identical to the parent process (the most obvious difference is that the new process has a different process ID). In particular, fork (conceptually) must copy all the ...
10
Conceptually, a library function is part of your process.
At run-time, your executable code and the code of any libraries (such as libc.so) it depends on, get linked into a single process. So, when you call a function in such a library, it executes as part of your process, with the same resources and privileges. It's conceptually the same as calling a ...
8
There are in fact three gradations in system calls.
Some system calls return immediately. “Immediately” means that the only thing they need is a little processor time. There's no hard limit to how long they can take (except in real-time systems), but these calls return as soon as they've been scheduled for long enough.
These calls are usually called ...
8
In "Advanced Programming in the UNIX Environment", W. Richard Stevens says it is a performance optimization:
By specifying the highest descriptor we're interested in, the kernel can avoid going through hundred of unused bits in the three descriptor sets, looking for bits that are turned on.
(1st edition, page 399)
If you are doing any kind of UNIX ...
8
I'm pretty sure that you are looking at legacy concerns. Recall that the Perl5 manual was released in 1994 and that it was just an edit of Perl4's manual from 1991. In those days it could probably be said about the oft-named Nightmare File System that "it isn't how well the bear dances that amazes, but that it dances at all".
NFS2 in the 1991 epoch was ...
7
There's not really such a thing as a "library call". You can call a function that's linked to a shared library. And that just means that the library path is looked up at runtime to determine the location of the function to call.
System calls are low level kernel calls handled by the kernel.
7
All modern operating systems support multitasking. This means that the system is able to execute multiple processes at the same time; either in pseudo-parallel (when only one CPU is available) or nowadays with multi-core CPUs being common in parallel (one task/core).
Let's take the simpler case of only one CPU being available. This means that if you ...
7
The other answers here seem to be largely geared towards modern versions of Linux, so if you happen to use git on an OS that doesn't have locate, whereis, which, or apropos (like Solaris, HPUX, etc), then there is always the old standby find.
find / -name git
One some older versions of the systems listed above, you may need a -print option supplied to ...
5
Summary: you're correct that receiving a signal is not transparent, neither in case i (interrupted without having read anything) nor in case ii (interrupted after a partial read). To do otherwise in case i would require making fundamental changes both to the architecture of the operating system and the architecture of applications.
The OS implementation ...
5
If you type man man in your shell, you will see the list of the manual sections
2 System calls (functions provided by
the kernel)
3 Library calls (functions
within program libraries)
For instance, you will find chmod in the section 2 of the manual when typing man chmod. And fprintf in the section 3.
5
System calls, messaging passing (as described in the Wikipedia article), and interrupts are all things that cause a context switch or a switch from user to kernel mode. As you likely know:
kernel mode: programs have a flat or real view of memory, and programs can read/write freely to all memory and all hardware devices directly without restriction.
user ...
5
As seen earlier, vfork does not allow the child process to access the parent's memory. exit is a C library function (that's why it's often written as exit(3)). It performs various cleanup tasks such as flushing and closing C streams (the files open through functions declared in stdio.h) and executing user-specified functions registered with atexit. All these ...
5
It is not possible because system call table (called sys_call_table) is a static size array. And its size is determined at compile time by the number of registered syscalls. This means there is no space for another one.
You can check implementation for example for x86 architecture in arch/x86/kernel/syscall_64.c file, where sys_call_table is defined. Its ...
4
There are standard error values, defined in errno.h. You can look at this file on your system to see the numerical values. On most systems, they're in /usr/include/errno.h or a file that it includes. On Linux, most are in /usr/include/asm-generic/errno-base.h or /usr/include/asm-generic/errno.h, with a few more in /usr/include/bits/errno.h.
If you have a ...
4
From the shell, you can run perror:
$ perror 123
OS error code 123: No medium found
That comes with MySQL.
If you don't have MySQL, you can use Perl or Python, e.g.:
$ perl -MPOSIX -e 'print strerror(123)'
No medium found
$ python -c 'import os; print os.strerror(123)'
No medium found
In a C program you can use the function with the same name:
...
4
You can use the Glibc manual as a reference. It's not for absolute beginners, but if you're reasonably fluent in C you should be able to read a section and write a working program.
You can find the source of the GNU tools on the GNU website; the easiest way to get it is to obtain the source packages on your Linux distribution (e.g. apt-get source coreutils ...
4
Two of the basic fundamentals of UNIX philosophy are
To make small programs that do one thing well.
and expect the output of every program to become the input to another,as
yet unknown,program.
The use of pipes let you leverage the effects of these two design
fundamentals to create extremely powerful chains of commands to achieve
your desired result.
...
4
Can't be done. From the exec(3p) man page:
Signals set to be caught by the calling process image shall be set to the
default action in the new process image.
You would have to write a preload SO which would hook up the signal handlers before the program started.
4
I believe that the idea of the socket being unavailable to a program is to allow any TCP data segments still in transit to arrive, and get discarded by the kernel. That is, it's possible for an application to call close(2) on a socket, but routing delays or mishaps to control packets or what have you can allow the other side of a TCP connection to send data ...
4
No, you can't perform system calls directly because the shell running under Terminal doesn't give you low level access to memory that you would need to call system calls and deal with the results. The shell's job is to make it easy for you to run whole programs. Some of these programs give you a more convenient interface to system calls and other operating ...
4
When a writer writes to a pipe and the pipe is full (its size is limited to a few kilobytes), its process blocks until one of the readers frees some space. Similarly, when a reader reads from a pipe, its process blocks until there is something there.
There are also asynchronous writes and reads that a programmer can use to queue up these reads and writes.
...
3
Message passing is a higher level concept of one process sending a message to another. It is implemented by a system ( kernel ) call, asking the kernel to pass the message to the other process. System calls ask the kernel to perform various services for the process. They are implemented by a software interrupt / system trap, which causes the cpu to save ...
3
There are two aspects: the ways system calls signal that an error occurred, and the way what error occurred is reported.
Most system calls signal that an error occurred by returning -1, but this is not completely universal (for example, some system calls are always successful, e.g. getpid).
If you know an error occurred, the error code is always in errno¹. ...
3
I don't know for sure, since I'm not one of the designers of select(), but I'd say it's a performance optimization. The calling function knows how many file descriptors it put in the read, write and except FDs, so why should the kernel figure it out again?
Remember that in the early 80s, when select() got introduced, they didn't have multi-gigaghertz, ...
3
System calls are handled directly by the kernel.
Library calls are handled by a dynamic library. The program making the library call must first import that library, before the call will work. The library calls themselves may use system calls.
Sometimes libraries are provided as "front-ends" to system calls, to provide extra functionality or ease of use ...
3
To get the path to the installed program you either use whereis or which. If you happen to forget it's name, you can useapropos with a synonym or description of your utility, e.g. apropos "version control" will find git. Following that is of course the whatis command to briefly summarize the function of a program. This does however not apply to all programs ...
3
A process's resident set size is the amount of memory that belongs to it and is currently present (resident) in RAM (real RAM, not swapped or otherwise not-resident).
For instance, if a process allocates a chunk of memory (say 100Mb) and uses it actively (reads/writes to it), its resident set size will be about 100Mb (plus overhead, the code segment, etc.).
...
3
system() is equivalent to fork() + exec() + wait(); this means when a process run system() function it creates a new process and waits the end of this process. The new process executes the command in it's own environment, when it has finished the caller receives the signal child.
For further information man exec man system
"exec replaces the current ...
Only top voted, non community-wiki answers of a minimum length are eligible