Hot answers tagged

18

The question asks about two types of programs: programs which interact with the user in the shell, and programs which do not interact with the user in the shell. In the first case, programs which interact with the user in the shell are designed to run to completion before returning control to the shell. Nothing special is done. The second case is more ...


17

It depends on whether your application is a computational one (like this) or interactive. For a computational application, full utilisation of the CPU(s) is your goal, as that means that the result is ready sooner. Anything that causes that utilisation to go down is an opportunity for improvement (e.g. waiting on I/O). For an interactive application, any ...


4

There's no general answer. Under modern Linux, you can look in /proc/$PID where $PID is the numerical process ID. You can get it out of the top output. ls -l /proc/$PID/exe will show you where exe is a symbolic link to. That's the full path to the a.out executable.


4

Processes are managed by the kernel. The kernel doesn't care how the programmer allocates variables. All it knows is that certain blocks of memory belong to the process. The C runtime matches C memory management features to kernel features: automatic variables go into a memory block called “stack” and dynamic storage (malloc and friends) go into a memory ...


3

Most Unix variants allocate process IDs sequentially: 1, 2, 3, 4, ... When the largest possible PID value is reached, they start again at 1, skipping PIDs that already exist. This is not an obligation. For example, OpenBSD assigns PIDs randomly, not sequentially; this is also an option on FreeBSD. The goal is improved security, though the benefits are ...


3

You can use lsof (available for just about any Unix variant, but often not part of the default installation) to list all the files a process is using. “Using” includes open file descriptors as well as closely related concepts such as which executable the process is running. The executable has txt in the FD column, for obscure historical reasons. $ lsof ...


3

Look at the man page for fork(2). A child process inherits the parent's file descriptors, including standard input and standard output. For a single command, the shell simply lets the child process inherit those descriptors and write its output to the terminal. For a pipeline, it forks each process, sets up a pipe between the output of one and the input of ...


2

I don't use htop, but judging from the man page it looks like you could use the space bar to "tag" a process, then the F9/k kill function will apply only to that process. Space Tag or untag a process. Commands that can operate on multiple processes, like "kill", will then apply over the list of tagged processes, instead of the currently highlighted ...


2

You didn't have a nohup process. Your search found an instance of grep which was searching for nohup, but by the time you got your next prompt, the grep process had already terminated. You're actually looking for a python instance. ps aux | grep python | grep manage.py # This will show you the process you're looking for kill $(ps aux | grep python | grep ...


2

You can use something like this while sleep 1;do ps -eo start_time,pid,euser,args:100 --sort start_time;done This will list all processes running in order of start time although it will be latest at the bottom. The loop update every second, if you need a finer time period change the sleep as needed. If you want the latest at the top you can pipe into tac ...


2

You could install the package nethogs if it is available for your system. This command is similar to top and will show you your running processes and how much network traffic they are generating. Use this command sequence: nethogs nethogs my_interface(s) If nethogs is not available you might try the iptraf command which will sort connections by usage. ...


2

To have your way works you have to fix the awk syntax and use the system function to execute commands in awk: pgrep firefox | awk '{system("kill "$1)}' Then you have your own-made (wheel reinvented) equivalent of: pkill firefox as pointed out in your question comments.


2

From the ps man page, the status field will tell you if a thread is on the run queue (use the 'L' option to see threads) -- D uninterruptible sleep (usually IO) R running or runnable (on run queue) S interruptible sleep (waiting for an event to complete) T stopped by job control signal t stopped by debugger during the tracing W ...


2

If you run ps ax without the grep, you'll see the column headers: PID TT STAT TIME COMMAND ?? is in the TT column -- that's the controlling terminal for the process. The ?? indicates that the process isn't associated with a terminal. The U in the STAT column indicates that the process is in the uninterruptible sleep state. That explains why you ...


2

Often, having given a long-running command, when you want to prepare the next command to run afterwards, you use shell job control to achieve it. Eg, you have given command1, not with an &, and then you want to give command2, so you suspend the current running command by typing control-z. You now have the shell prompt again, so you type fg; command2 ...


2

If the load stay low and the process count stay pretty constant, that just means short lived processes are spawn during the ten second period. Twenty seven processes per second might not be a problem at all so there might be nothing to fix. On the other hand, that might be a bogus daemon or something trying to launch a process that quickly fails and doing ...


2

Of course it's good. The CPU's sole raison d'être is to be used by applications. The entire hw+os combo exists for this single purpose. Why wouldn't it be good to consume as much cpu as there is in the system?


1

/proc/[pid] disappears when the program exits. See this: https://superuser.com/questions/365576/lifetime-of-the-symlinks-from-the-file-descriptors-in-proc-pid-fd edit: The wait man page says The wait() function shall suspend execution of the calling thread until status information for one of the terminated child processes of the calling ...


1

If you just want to run commands as soon as the previous one has completed, you can separate them with ; like this: command1 ; command2 Or, if you only want to run the second command if the first command returns true, like this: command1 && command2


1

iotop is your friend (assuming your server runs Linux).


1

You could try killall pleeease to kill all instances of pleeease; it will tell you when it couldn't find any. ps -A | grep pleeease to filter the output of ps for the process you're looking for, then use kill with the process ID. pgrep pleeease as a variation of 2. to just get the PID(s) instead of the complete ps line (which may make it hard to ...


1

If nothing else, your shell script creates a process for each command such as ps, cut, tail, etc., in that loop. You could only observe the systems with an application (one process...) which scanned the /proc filesystem looking for relevant changes. Further reading: How to continuously monitor process creation in Linux? Monitor all newly spawned ...


1

See kernel/sched/loadavg.c which has a long and excellent comment at the start explaining the derivation of load average from a exponentially decaying average of the number of runnable threads (the "run queue") plus the number of uninterruptable threads (waiting on I/O or waiting on a lock). Here's the essence of the comment, but it is worthwhile reading in ...


1

Not sure if this is too old to answer (first time answering a question), but the AIX equivalent you're looking for is ps -ef | awk '$NF~/[o]ra_pmon/ {print $2,$NF}' e.g. [oracle@aixbox ]$ ps -ef | awk '$NF~/[o]ra_pmon/ {print $2,$NF}' 8061108 ora_pmon_XXX 38993950 ora_pmon_YYY


1

Whenever a process exits either gracefully or through SIGINT,SIGTERM,SIGKILL etc, the exit system call is invoked. Part of the exit call's job is to reclaim any resources that were being used by the process. Essentially, whenever the OS sees an exit status (success or not) being returned, two things happen: SIGCHLD is sent to the parent process to let the ...


1

For applications like Firefox, I just use killall firefox. man killall


1

This is probably not a complete solution, but it may help. See this htop example: To change the refresh interval of the htop output, use the -d command line option. “htop -d x”. Where x is referred in thenths of seconds. htop -d 10 So you could change the rate to 30, after which the refresh rate goes to 3 seconds. This is no guarantee, but it makes ...


1

Unfortunately, your question is not specific on what you're wanting. Here's a few examples, though. Hopefully they are what you're wondering about. Note: There are seriously billions of ways of achieving these things. Find the one that's right for you with experimentation. Top 5 CPU Hogs So you want the top 5 cpu hogs. Got it. You can do this. ps -Ao ...


1

The POSIX standard defines that $$ always is the pid of the main shell. If you run a process in the background, $! returns the pid of the last background process.


1

The purpose of the operating systems is to handle this for you, Windows, Mac OS, Linux, the two fundamental purposes of all of them are scheduling and hardware interface. This question has nothing to do with Linux or Unix.



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