Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Processes in Linux2

The document discusses various Linux processes including foreground and background processes. It describes how to view running processes using commands like ps and kill processes. It also covers utilities for network communication and task scheduling.

Uploaded by

apiit.sachin12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Processes in Linux2

The document discusses various Linux processes including foreground and background processes. It describes how to view running processes using commands like ps and kill processes. It also covers utilities for network communication and task scheduling.

Uploaded by

apiit.sachin12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Processes in Linux

Foreground Processes

By default, every process that you start runs in the foreground. It gets its input from the keyboard
and sends its output to the screen.

we can see this happen with the ls command.

$ ls ch*.doc

While a program is running in the foreground and is time-consuming, no other commands can be
run (start any other processes) because the prompt would not be available until the program
finishes processing and comes out.

Background Processes

A background process runs without being connected to your keyboard. If the background process
requires any keyboard input, it waits.

The advantage of running a process in the background is that you can run other commands; you
do not have to wait until it completes to start another!

The simplest way to start a background process is to add an ampersand (&) at the end of the
command.

$ls ch*.doc &

Listing Running Processes

It is easy to see your own processes by running the ps (process

status) command as follows −

$ps
PID TTY TIME CMD
18358 ttyp3 00:00:00 sh
18361 ttyp3 00:01:31 abiword
18789 ttyp3 00:00:00 ps

One of the most commonly used flags for ps is the -f ( f for full) option, which provides more
information
$ps -f
UID PID PPID C STIME TTY TIME CMD
amrood 6738 3662 0 10:23:03 pts/6 0:00 first_one
amrood 6739 3662 0 10:22:54 pts/6 0:00 second_one
amrood 3662 3657 0 08:10:53 pts/6 0:00 -ksh
amrood 6892 3662 4 10:51:50 pts/6 0:00 ps -f

Sr.No. Column & Description

UID
1
User ID that this process belongs to (the person running it)

PID
2
Process ID

PPID
3
Parent process ID (the ID of the process that started it)

C
4
CPU utilization of process

STIME
5
Process start time

TTY
6
Terminal type associated with the process

TIME
7
CPU time taken by the process

CMD
8
The command that started this process

Stopping Processes

Ending a process can be done in several different ways. Often, from a console-based command,
sending a CTRL + C keystroke (the default interrupt character) will exit the command

kill command to kill the process as follows −

$ps -f
UID PID PPID C STIME TTY TIME CMD
amrood 6738 3662 0 10:23:03 pts/6 0:00 first_one
amrood 6739 3662 0 10:22:54 pts/6 0:00 second_one
amrood 3662 3657 0 08:10:53 pts/6 0:00 -ksh
amrood 6892 3662 4 10:51:50 pts/6 0:00 ps -f
$kill 6738
Terminated

kill command terminates the first_one process. If a process ignores a regular kill command, you
can use kill -9 followed by the process ID as follows –

$kill -9 6738
Terminated

Top

It is an interactive diagnostic tool that updates frequently and shows information about physical
and virtual memory, CPU usage, load averages, and your busy processes.

top - 16:56:36 up 2 days, 22:30, 0 users, load average: 0.83, 1.16, 1.11

Tasks: 10 total, 1 running, 9 sleeping, 0 stopped, 0 zombie

%Cpu(s): 8.1 us, 2.9 sy, 0.9 ni, 83.6 id, 2.7 wa, 0.0 hi, 1.8 si, 0.0 st

MiB Mem : 32090.3 total, 1267.8 free, 5300.5 used, 25522.0 buff/cache

MiB Swap: 0.0 total, 0.0 free, 0.0 used. 24699.8 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

7 user 38 18 971336 89944 43640 S 2.3 0.3 0:02.20 node

1071 user 38 18 7800 3384 3016 R 0.3 0.0 0:00.01 top

1 user 20 0 2780 944 856 S 0.0 0.0 0:00.01 tini

6 user 38 18 2892 1052 956 S 0.0 0.0 0:00.00 sh

211 user 38 18 15444 8772 7240 S 0.0 0.0 0:00.01 sshd

894 user 38 18 7524 6656 3532 S 0.0 0.0 0:00.03 bash

907 user 38 18 7524 6708 3588 S 0.0 0.0 0:00.03 bash

912 user 38 18 7524 6632 3508 S 0.0 0.0 0:00.03 bash

922 user 38 18 7524 6728 3604 S 0.0 0.0 0:00.04 bash


1029 user 38 18 7524 6688 3564 S 0.0 0.0 0:00.03 bash

Zombie and Orphan Processes

Normally, when a child process is killed, the parent process is updated via a SIGCHLD signal.
Then the parent can do some other task or restart a new child as needed. However, sometimes the
parent process is killed before its child is killed. In this case, the "parent of all processes,"
the init process, becomes the new PPID (parent process ID). In some cases, these processes are
called orphan processes.

Ulnix / Linux - Network Communication Utilities

The ping Utility

The ping command sends an echo request to a host available on the network. Using this
command, you can check if your remote host is responding well or not.

The ping command is useful for the following −

• Tracking and isolating hardware and software problems.


• Determining the status of the network and various foreign hosts.
• Testing, measuring, and managing networks.

Syntax

Following is the simple syntax to use the ftp command −

$ping hostname or ip-address

The ftp Utility

Here, ftp stands for File Transfer Protocol. This utility helps you upload and download your file
from one computer to another computer.The ftp utility has its own set of Unix-like commands.
These commands help you perform tasks such as −

• Connect and login to a remote host.


• Navigate directories.
• List directory contents.
• Put and get files.
• Transfer files as ascii, ebcdic or binary.
Syntax

Following is the simple syntax to use the ftp command −

$ftp hostname or ip-address

r.No. Command & Description

put filename
1 Uploads filename from the local machine to the remote
machine.

get filename
2 Downloads filename from the remote machine to the local
machine.

mput file list


3 Uploads more than one file from the local machine to the
remote machine.

mget file list


4 Downloads more than one file from the remote machine to the
local machine.

prompt off
5 Turns the prompt off. By default, you will receive a prompt to
upload or download files using mput or mget commands.

prompt on
6
Turns the prompt on.

Dir
7 Lists all the files available in the current directory of the
remote machine.

cd dirname
8
Changes directory to dirname on the remote machine.

lcd dirname
9
Changes directory to dirname on the local machine.

Quit
10
Helps logout from the current login.
The telnet Utility

There are times when we are required to connect to a remote Unix machine and work
on that machine remotely. Telnet is a utility that allows a computer user at one site to
make a connection, login and then conduct work on a computer at another site.

Once you login using Telnet, you can perform all the activities on your remotely
connected machine. The following is an example of Telnet session −

C:>telnet amrood.com
Trying...
Connected to amrood.com.
Escape character is '^]'.

login: amrood
amrood's Password:
*****************************************************
* *
* *
* WELCOME TO AMROOD.COM *
* *
* *
*****************************************************

Last unsuccessful login: Fri Mar 3 12:01:09 IST 2009


Last login: Wed Mar 8 18:33:27 IST 2009 on pts/10

{ do your work }

$ logout
Connection closed.
C:>

The finger Utility

The finger command displays information about users on a given


host. The host can be either local or remote.
Get information about a specific user available on the local machine

$ finger amrood
Login: amrood Name: (null)
Directory: /home/amrood Shell: /bin/bash
On since Thu Jun 25 08:03 (MST) on pts/0 from 62.61.164.115
No mail.
No Plan.

Check all the logged-in users on the remote machine −

$ finger @avtar.com
Login Name Tty Idle Login Time Office
amrood pts/0 Jun 25 08:03 (62.61.164.115)

Get the information about a specific user available on the remote


machine −

$ finger amrood@avtar.com
Login: amrood Name: (null)
Directory: /home/amrood Shell: /bin/bash
On since Thu Jun 25 08:03 (MST) on pts/0 from 62.61.164.115
No mail.
No Plan.

Task Scheduling:

1. at Command:
• Description: The at command schedules a one-time task to run at a specific time in the future.
• Usage:
• at: Schedule a task to be executed once at a specific time.
• atq: List the pending at jobs for the current user.
• atrm: Remove a pending at job.
• Syntax:
• at <time>: Schedules a new job to run at the specified time.
• Example: at now + 1 hour

2. batch Command:
• Description: The batch command schedules tasks to run when system load levels permit.
• Usage:
• batch: Schedule a job to be executed when system load levels drop below a certain threshold.
• atq: List the pending batch jobs for the current user.
• atrm: Remove a pending batch job.
• Syntax:
• batch: Schedules a job to be executed when the system load is low.
• Example: batch

3. cron:
• Description: cron is a time-based job scheduler that runs recurring tasks at predefined intervals.
• Files:
• /etc/crontab: System-wide cron jobs configuration file.
• /etc/cron.d/: Directory for system-wide cron job files.
• /var/spool/cron/crontabs/ : Directory for individual user cron jobs files.
• Commands:
• crontab -e: Edit the current user's crontab file.
• crontab -l: List the current user's cron jobs.
• crontab -r: Remove the current user's cron jobs.
• Cron Syntax:
• Minute (0-59), Hour (0-23), Day of Month (1-31), Month (1-12), Day of Week (0-7 where 0 and 7
represent Sunday).
• * indicates all possible values.
• Example: 0 3 * * * /path/to/command (Runs a command at 3:00 AM daily).

Examples:
1. Schedule a job to run a script at 2:30 PM:

at 2:30 PM /path/to/script.sh CTRL+D

2. Schedule a job to run a command when system load is low:

batch /path/to/command CTRL+D

3. Schedule a job to run a command daily at 4:30 AM:

crontab -e 30 4 * * * /path/to/command

You might also like