Tag Info

Hot answers tagged

10

The kernel does job scheduling and provides system calls. When a process is running, the kernel schedules its runtime - especially it assigns a PID to it - such information is stored inside the kernel address space, in data structures (e.g. inside a task struct). Thus, when a process calls the getpid() system call, the kernel just has to look in the task ...


8

As mentioned in a comment and without seeing any of your code or other information (which would not be on-topic here anyway) all I can say is your program appears to be IO bound. The means while your calculations could use more of your CPU, they are having to wait on data and spending many cycles waiting rather than calculating. This can be due to the way ...


6

A function would probably be better, yes, but in this case the problem probably is because you are using double quotes around it. The $ variables get expanded before the assignment to the alias. You can use a single quote on the outside instead, or, because you already have single quotes, escape the $ with \: alias findrails_pid="ps aux | grep rails | ...


5

Well, the exact sequence may vary, as there might be a shell alias or function that first gets expanded/interpreted before the actual program gets executed, and then differences for a qualified filename (/usr/libexec/foo) versus something that will be looked for through all the directories of the PATH environment variable (just foo). Also, the details of the ...


5

How can I see the raw memory data used by an application... Once you have obtained the process' PID (using ps(1) or pidof(8) for instance), you may access the data in its virtual address space using /proc/PID/maps and /proc/PID/mem. Gilles wrote a very detailled answer about that here. ... and all the files its accessing in my filesystem, network ...


5

When a system call is executed, there is a privilege switch, i.e. the executed code is allowed to execute more instructions and access data forbidden to userland code. There is however no process context switch so the kernel code is still running in the calling process context. That means the kernel does not need to search which process is calling it, it ...


4

Killing a parent process won't kill child processes unless the parent traps and resends the signal. Killing a process group with TERM sends the TERM signal to all members of the process group so that's the way to go, but you should make sure that the parent starts a process group (or that the parent's parent starts a process group and you don't care about ...


4

It's the shell; as you will see via the ps command, in that case the PPID of less will be the PID of the shell. The processes ls and less haven't much in common; it's just that the stdout of the former is piped in the stdin of the latter.


4

In a single CPU system, there is a global variable that points to the proc structure of the running process or the current thread. The proc structure contains the process id. In a multi CPU system, there is either a similar pointer for every CPU or the MMU context is used to set up such a global variable for the syscall. int64_t getpid(void) { ...


3

You can get this information through the virtual /proc file-system (under Linux only). Try to run this command when the process is running (replace the <pid> by the PID of the observed process): grep 'VmSize' /proc/<pid>/status Beware, you have to have read access to the process to get these information (you cannot access it if you do not ...


3

Partial answer: You can see the files it accesses in real-time by using strace something.sh Specifically, it shows you every system call made by the process.


3

Indeed you need to use /proc/; so read carefully proc(5). For process 1234 you want to read /proc/1234/maps (or /proc/1234/smaps) to get the address space, and to read /proc/1234/status & /proc/1234/statm For your own process (programmatically) use /proc/self/maps, /proc/self/status, /proc/self/statm Notice that memory usage is a very ambiguous term ...


3

A defunct (zombie) process is a process that has terminated, but its parent process hasn't yet done a wait*() on it. If the parent process terminates before the child process, the child process gets re-parented to init (pid 1), and init performs the wait*() on it when it dies. Therefore, every defunct process much be a child of some non-init process.


3

Now that we know what you really want... Use -o to select your desired fields. For instance: $ ps -eo pid,ppid,%cpu,%mem,args PID PPID %CPU %MEM COMMAND 1 0 0.0 0.0 /usr/lib/systemd/systemd --system --deserialize 22 ...more procs... 1522 3205 0.0 0.0 nginx: worker process 1523 3205 0.0 0.0 nginx: worker process 1525 3205 0.0 0.0 ...


2

Some experiments: $ yes | sleep 10m & [1] 32395 32396 $ pstree -pa $(ps -o ppid= -p $(pgrep yes)) zsh,29630 ├─pstree,32402 -pa 29630 ├─sleep,32396 10m └─yes,32395 As can be seen, the parent of both processes is the shell. With a longer pipeline: $ sleep 10m | sleep 10m | sleep 10m | sleep 10m & [1] 32320 32321 32322 32323 $ pstree -pa $(ps ...


2

4.89 of lsof supports displaying endpoint options. Quoted from lsof.8: +|-E +E specifies that process intercommunication channels should be displayed with endpoint information and the channels of the endpoints should also be displayed. Currently only pipe on Linux is implemented. Endpoint information is displayed in the NAME column ...


2

You're running Ubuntu 14.04, which uses upstart as its init process. As we can see from looking at /etc/init/cups.conf, it has a respawn stanza, so by default when the cupsd process ends, another one will be started. # kill -TERM -3390 # tail -1 /var/log/syslog Aug 9 14:22:49 ubuntu kernel: [ 283.270126] init: cups main process ended, respawning You ...


2

That pretty much means your apps are IO bound--your hardrive/network, etc. can't keep up with your processor and consequently, the processor spends a lot of time waiting on IO data, not using its full potential. If the IO your apps depend on is the network and you aren't downloading at your full bandwith, you might get an efficiency increase by adding more ...


2

You can't kill a zombie. As the name indicates, it's dead. A zombie is not a real process, it's only an entry in the process table, waiting for the parent to take notice. A process doesn't change its process ID. If you see new process IDs appear, it's because something is spawning them. If the process you're killing is being monitored, the monitoring ...


2

PID 4036 is not the root of the process tree; that's PID 1. You asked for the subtree with 4036 at the root, so of course you don't see its parent. But it has one. Every process has a parent except PID 1.


2

/proc/net/dev contains statistics about network interfaces, while /proc/<pid>/net/dev contains statistics about network interfaces from the process' point of view. I suppose that if a process runs on a network namespace (see man ip-netns) where it has access only to a limited set of interfaces, only these will show up in /proc/<pid>/net/dev.


2

What you can do is open the file and pass the file descriptor to the other process over a unix-domain socket using the sendmsg system call with SCM_RIGHTS. You can also determine what user ID is running the remote process by reading the SO_PEERCRED socket option. So taken together this allows you to grant control to a specific process, but it's not as ...


2

du works by scanning through the directory recursively, counting up the size of all the files & directories. Something like: start with the first directory given on the command line. stat the directory to determine its size, add that to the total read the first entry (file or subdirectory name) from the directory if it's a file, stat it and add it to ...


1

The four records have different permissions, so they can't be merged. The r-xp entry describes a block of executable memory (x permission flag). That's the code. The r--p entry describes a block of memory that is only readable (r permission flag). That's static data (constants). The rw-p entry describes a block of memory that is writable (w permission ...


1

You can create a recursive script. eg in file /tmp/run #!/bin/bash depth=${1:-5} f(){ let depth-- if [ $depth -gt 0 ] then $0 $depth else sleep 10 fi } f then chmod +x /tmp/run and do /tmp/run 10.


1

Assuming a textbook example shell (for code clarity) that is already running (so the dynamic linker is done), the commands you mention will require the shell to make the following system calls: read: gets the next command in this case gcc fork: two process are needed, we assume the parent has pid 500 and the child for illustration. the parent will call ...


1

Do you have a link for the particular 7-state process model? Generally, blocked processes are put on queues belonging to the events they are waiting for, so the answer would be no. Only the blocked/ready processes would be on a run queue (and even then, depending on the scheduler and number of cores there could be multiple run queues).


1

The DHCP client daemon (dhcpdc, dhclient, etc) are programs that are started during the init process. These programs are not always directly invoked by init, but rather the program that handles networking will do this when an interface is configured to use dhcp. For example, netctl is one such program distros use to manage the networking interfaces. This ...


1

Use chroot (manual here) chroot yourDirectory yourCommand


1

@derobert explained how du operates. He didn't mention that unless you have an absolutely huge number of small files / directories (so the metadata takes a huge amount of memory), then running du again right away usually produces a result much more quickly. One large file doesn't make du slow, but copying it is more likely to push directory caches out of ...



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