Make a Suspended Pid Run Again

4. Manipulating processes in Linux¶

Equally you work more with linux you will have occasion to monitor the number of running programs (processes) on the car you lot are logged into. Y'all may exist curious, for example, about how much cpu and memory they are consuming. You may also be curious about resource consumption for other people's programs. The general purpose procedure status command ps is the tool for this task. For example, issue ps with the (well-nigh) all processes -a and all users -u switches:

Y'all should see something like:

_images/ps.png

Firstly, ignore the warning on the first line. ps is on of those weird linux commands that accepts 2 ways of formatting switches. If it bothers yous, you lot can remove the nuance from the command line and rerun. (But so the command'southward format is dissimilar from what I accept been telling y'all about switches and more defoliation will result.) The data returned is in tabular format so read the column headings. Looking at the first cavalcade we run into that user "setiawan" is one decorated user. Y'all likewise run into the user 'root" and the user "coan" (me). Y'all will undoubtedly come across your username. The next column labels the process id (PID) of the listed processes. This is a unique numerical identifier. Next are "%CPU" and "%MEM" showing the fraction of cpu and memory consumed by a given process. These are important considering if the machine is running slowly, it is frequently due to these fractions being high. Skip the adjacent four columns until you come to the 2 columns "START" and "TIME". These guys tell y'all when you started the given process. Finally, we come to the concluding column, "COMMAND" which lists the actual process name.

If you merely want to meet but your processes, y'all take at least two choices. You tin exist lazy and just type:

Or, if you desire more information, you tin use a pipe:

where I used my username as an case. I will leave it to you lot and the man pages to run across how to get a long listing from ps using one of its many switches.

Sometimes you launch a procedure (plan) that consumes so much of the cpu that information technology dramatically slows the motorcar so that useful piece of work ceases. You issue the ps command and verify that that the process is indeed a cpu hog. Rather than wait for the procedure to end, you lot can hasten its demise. This is done using the kill command and the PID of the process. Nosotros'll see an case of this shortly.

Linux considers user processes to be in 1 of three states: foreground, background and suspended. A foreground procedure is one that is executing in the window you lot typed it in and you cannot go the cursor back until ]the process completes. This is the way you have been running up until at present (with the exception of gedit .) As you have already seen, you tin can run a process backside the scenes, then to speak, as you did with gedit . Finally, there is a sort of hibernation state – the suspended country. Here the process is withal "living" just is non actively executing. Yous are able to alter merely those processes that you initiated ("own" is the jargon).

To run across process break in activity, consider commencement the useful linux command sleep that delays the execution start time of a command by some number of seconds that the user specifies:

Note that the cursor does not return until 10 seconds take elapsed and just then does ls execute.

If you at present issue:

and then type Ctrl-Z (holding down simultaneously the Ctrl key and the "z" key), you will suspend the sleep process. Attempt It! You should run into:

This sleep` process didn't dice, it'south, well, suspended. If yous next type the jobs control, linux will tell y'all about suspended processes (as well every bit any background procedure running)

and linux will answer with:

[1] + Suspended    slumber 100

The number in brackets [] tells you the process' "job number." To button this task to the background where information technology will proceed to run, issue:

If you only have 1 suspended process, you tin merely type

and the process volition be "backgrounded."

To bring a suspended process to the foreground, use the foreground command fg and the process' chore number:

The process so starts executing as if you had never suspended it. Again, if yous have only 1 suspended process, you lot can "foreground" it past issuing

You tin delete a suspended process past issuing the impale command along the process's job number. Try information technology wilh sleep 100 :

By the way, if yous just want to impale a process running in the foreground and not even bother to put information technology in the groundwork, you can consequence a "Ctrl-C" control (hold down simultaneously the Ctrl key and the "c" central). Try information technology with the sleep 100 . you should see the cursor render immediately.

Another way of killing processes is to issue impale` with the PID of the offending process. Linux has a control ``xclock to produce a clock face on your desktop and then you can lookout man the time. Launch it so information technology runs in the groundwork:

Discover xclock 's PID. Bold its PID is 87912, issuing:

volition eliminate the process and the clock face volition disappear. (The number 9 is a bit obscure but e'er works. Leaving off the ix sometimes does not piece of work. Read more on Linux/Unix.) Were you successful?

Finally, there is a kind of symmetry between foreground jobs and background ones. We saw how to movement foreground jobs to the background. we can practise the contrary. Consider the case of gedit:

Bold its chore number is 1, y'all can bring gedit from the background to the foreground using the foreground control fg :

You lot tin now kill it off past using one of the techniques in this chapter. Were yous successful?

4.1. Summary¶

Command Significant
ps -au list all current processes
control & run command in the groundwork
jobs list current jobs
bg %one push job number ane to the background
fg %1 bring job number 1 to the foreground
impale %i kill process with job number 1
impale -9 2132 kill process with PID 2132
Ctrl-C kill the process running in foreground
Ctrl-Z suspend the process running in foreground
sleep 15 filibuster execution for 15 seconds
xclock place a running clock on your desktop

hazeltinesplight.blogspot.com

Source: http://www.physics.smu.edu/coan/linux/processes.html

0 Response to "Make a Suspended Pid Run Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel