LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2004, 08:55 AM   #1
merlin23
Member
 
Registered: Dec 2004
Location: Vienna
Posts: 46

Rep: Reputation: 15
get pid in bash


I want to get the pid of a process in a shell skript to put it into a variable...

it must be going something like

ps -e | grep myapp | grep regexp

but how to use a regexp , that it gives me all numbers from the beginning of the line to the next space?

maybe grep is not the right thing to extract
 
Old 12-07-2004, 09:37 AM   #2
bostontech
LQ Newbie
 
Registered: Dec 2004
Location: Boston
Distribution: all
Posts: 23

Rep: Reputation: 15
I think you might find the "pgrep" utility useful in this case.
man pgrep

BTG
 
Old 12-07-2004, 09:37 AM   #3
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
How about
Code:
   ps -e | grep myapp | awk '{print $1}'
Groetjes,

Kees-Jan
 
Old 12-07-2004, 09:38 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

This is one way of doing this:

ps -e | grep myapp | grep -v grep | awk '{ print $2 }'

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: how to get the PID of programs started? J_Szucs Programming 11 01-16-2012 03:08 AM
using bash to find the pid of a process called "name" poiuytrewq Linux - Newbie 3 10-25-2004 10:01 PM
bash script, monitoring running PID? thebover Programming 4 08-26-2004 03:42 PM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 11:32 PM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 10:28 PM


All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration