Hot answers tagged

347

System calls aren't handled like regular function calls. It takes special code to make the transition from user space to kernel space, basically a bit of inline assembly code injected into your program at the call site. The kernel side code that "catches" the system call is also low-level stuff you probably don't need to understand deeply, at least at ...


74

This probably doesn't answer your question directly, but I've found strace to be really cool when trying to understand the underlying system calls, in action, that are made for even the simplest shell commands. e.g. strace -o trace.txt mkdir mynewdir The system calls for the command mkdir mynewdir will be dumped to trace.txt for your viewing pleasure.


45

A good place to read the Linux kernel source is the Linux cross-reference (LXR). Searches return typed matches (functions prototypes, variable declarations, etc.) in addition to free text search results, so it's handier than a mere grep (and faster too). LXR doesn't expand preprocessor definitions. System calls have their name mangled by the preprocessor ...


45

source or the equivalent but standard dot . do not execute the script, but read the commands from script file, then execute them, line by line, in current shell environment. There's nothing against the use of execution bit, because the shell only need read permission to read the content of file. The execution bit is only required when you run the script. ...


33

Let's analyse the factors... Analysis: DEPENDENCIES ACCORDING TO PLATFORM: There are some issues that arise in an environment where developers are creating and maintaining several architecture-specific variants of an application: Different source code is required for different variants — Different UNIX-based operating systems may use different functions ...


29

All software are programs, which are also called source packages. So all source packages need to be built first, to run on your system. The binary packages are one that are already build from source by someone with general features and parameters provided in the software so that a large number of users can install and use it. Binary packages are easy to ...


28

In tcsh, $_ at the beginning of the script will contain the location if the file was sourced and $0 contains it if it was run. #!/bin/tcsh set sourced=($_) if ("$sourced" != "") then echo "sourced $sourced[2]" endif if ("$0" != "tcsh") then echo "run $0" endif In Bash: #!/bin/bash called=$_ [[ $called != $0 ]] && echo "Script is being ...


26

It's usually plain C. The commands ls and pwd come from the GNU Coreutils package in (most?) Linux distributions (and maybe some other systems). You can find the code on their homepage. For coreutils specifically, you build them with the usual steps: after unpacking the source, issue: ./configure --prefix=/some/path # type ./configure --...


23

A source file contains the original code as written by the developer in whatever language he/she chooses (C, C++, Python etc),and is generic. It isn't specific to any distro and in many cases to any operating system. A package (RPM or DEB for example) is the binary executable (or interpreted script etc) pre-prepared for your particular distro. The task of ...


21

Welcome to unix.stackexchange.com! There's no easy answer to your question, and far better people than me have written entire books on the subject of the Linux kernel and operating systems in general. About the scope of the project: writing an operating system is not a simple task! Even a purposefully minimal OS like Minix is a pretty complex thing! To ...


21

The uname utility gets its information from the uname() system call. It populates a struct like this (see man 2 uname): struct utsname { char sysname[]; /* Operating system name (e.g., "Linux") */ char nodename[]; /* Name within "some implementation-defined network" */ char ...


19

Distribution kernel-header packages contain, as their name implies, only kernel header files (plus the necessary plumbing) that are required to build software like kernel modules. You shouldn't expect to find binary files at all in a kernel source directory, except for build output. (If you configure and build a kernel yourself, the kernel source directory ...


19

The -dev packages usually contain header-files, examples, documentation and such, which are not needed to just running the program (or use a library as a dependency). They are left out to save space. ArchLinux usually just ships these files with the package itself. This costs a bit more disk space for the installation but reduces the number packages you ...


18

System calls are usually wrapped in the SYSCALL_DEFINEx() macro, which is why a simple grep doesn't find them: fs/namei.c:SYSCALL_DEFINE2(mkdir, const char __user *, pathname, int, mode) The final function name after the macro is expanded ends up being sys_mkdir. The SYSCALL_DEFINEx() macro adds boilerplate things like tracing code that each syscall ...


18

I think that you could use $BASH_SOURCE variable. It returns path that was executed: pbm@tauri ~ $ /home/pbm/a.sh /home/pbm/a.sh pbm@tauri ~ $ ./a.sh ./a.sh pbm@tauri ~ $ source /home/pbm/a.sh /home/pbm/a.sh pbm@tauri ~ $ source ./a.sh ./a.sh So in next step we should check if path is relative or not. If it's not relative everything is ok. If it is we ...


18

The executable bit (unlike the rest) on nonsetuid and nonsetguid files isn't much of a security mechanism. Anything you can read, you can run indirectly, and Linux will let you indirectly read anything you can run but not directly read (that should be enough to punch a hole in the concept of non-set(g)uid x-bit being a security measure). It's more of a ...


17

Firstly, according to the File System Hierarchy Standards, the location of this installed package should be /opt if it is a binary install and /usr/local if it's a from source install. Pure binaries These are ready to use binaries. Normally they just need to be extracted to be installed. A binary package is going to be easy: sudo tar --directory=/opt -xv ...


16

Note: the .h file doesn't define the function. It's declared in that .h file and defined (implemented) elsewhere. This allows the compiler to include information about the function's signature (prototype) to allow type checking of arguments and match the return types to any calling contexts in your code. In general .h (header) files in C are used to ...


16

Bash is an interpreter; it accepts input and does whatever it wants to. It doesn't need to heed the executable bit. In fact, Bash is portable, and can run on operating systems and filesystems that don't have any concept of an executable bit. What does care about the executable bit is the operating system kernel. When the Linux kernel performs an exec, ...


15

As mentioned on LWN, the easiest is: git describe --contains f3a1ef9cee4812e2d08c855eb373f0d83433e34c If you don't want a local clone, gitweb's "plain" formatted commit contains the same info in the X-Git-Tag header. Unfortunately kernel.org switched over to cgit which apparently does not disclose this information. Previously it was possible to find it ...


13

Normally, the project will have a website with instructions for how to build and install it. Google for that first. For the most part you will do either: Download a tarball (tar.gz or tar.bz2 file), which is a release of a specific version of the source code Extract the tarball with a command like tar zxvf myapp.tar.gz for a gzipped tarball or tar jxvf ...


13

The data is stored in init/version.c: struct uts_namespace init_uts_ns = { .kref = { .refcount = ATOMIC_INIT(2), }, .name = { .sysname = UTS_SYSNAME, .nodename = UTS_NODENAME, .release = UTS_RELEASE, .version = UTS_VERSION,...


13

Apart from the other answers, I would like to add something: If you decide to compile a program by yourself, you need to think that compiling is not something you do only once. You will probably need to subscribe to the development mailing list of the applications you decided to compile and stay up to date with the new versions and, especially, the security ...


11

Building from source provides the following options which are not available when using a version from a binary package manager. Compiling from source allows you to: use processor-specific optimizations use the very latest version learn how compilation & linking work (suggestion from @mattdm) fix bugs, development work set compile-time options (e.g. ...


11

Debian Installer is actually a bunch of different packages, in several repositories. The Debian Wiki has a page on how to get the Debian Installer source: Make sure mr is installed, and: svn co svn://anonscm.debian.org/svn/d-i/trunk debian-installer cd debian-installer scripts/git-setup mr -p checkout Beware it'll take a while, as its ~480MB. The ...


10

I see three errors: Your assignment line is wrong: $NAME="a string" When you assign to a variable you don't include the $; it should be: NAME="a string" You're missing then; the conditional line should be: if [ -f $HOME/install.sh ]; then You're not quoting $NAME, even though it has spaces. The source line should be: . $HOME/install.sh "$NAME"


10

Michael Mrozek covers most of the issues and his fixes will work since you are using Bash. You may be interested in the fact that the ability to source a script with arguments is a bashism. In sh or dash your main.sh will not echo anything because the arguments to the sourced script are ignored and $1 will refer to the argument to main.sh. When you ...


10

Yes you can. Download it. But as you don't say what flavor of linux re you using here is couple of examples: Debian/Ubuntu related: # What package is the netstat executable in? apt-file search /usr/bin/netstat # Now download the source of that package apt-get source net-tools CentOS/Red Hat: yumdownloader --source net-tools


10

Unpack the files and then, in the directory that was created, look for a README or INSTALL file which will tell you what you need to know in order to install a package (e.g. dependencies, configuration options, commands to run etc...). Usually it boils down to ./configure, make then make install.


10

There is such a variety of platforms and software environments both *nix and other, that the software may be able to be run on, that allowing you to build an application (or library to use with applications) is the only realistic way to support as many combination of those components as a "good" software item does. Of course, licences such as the GPL ...



Only top voted, non community-wiki answers of a minimum length are eligible