LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-11-2004, 01:57 PM   #1
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Rep: Reputation: 30
another odd command usage


ok i have a program called sc_trans_linux

heres what i need bear with me


the program runs at system start

but i need the PID of the program


this command

kill -WINCH "PID"
changes the song (its a mp3 sourceclient for a shoutcast server)


at the start i want a basch script or something to find the pid of that program and export a variable for the PID so i can

kill -WINCH $variable
 
Old 05-11-2004, 02:03 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
What about:
PID=`ps -ef | grep sc_trans_linux | grep -v grep | awk {'print $2'}`
 
Old 05-11-2004, 02:09 PM   #3
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Original Poster
Rep: Reputation: 30
thanks that works
but what does the awk {'print 2'} fuction do

odviously it returns the pid number
but how does that work??
 
Old 05-11-2004, 02:19 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
To break it down:
Get all the system processes: ps -ef
Look for your program: grep sc_trans_linux
Ignore the grep itself: grep -v grep
Return column 2 of the line matched: awk {'print $2'}

The default field seperator for awk is white space but you can change it with --field-seperator if needed. The man page covers all the options in more detail.
 
Old 05-11-2004, 02:27 PM   #5
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Original Poster
Rep: Reputation: 30
thanks

how would i save that variable so i can use it in any terminal window??
 
Old 05-11-2004, 02:29 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You won't be able to use it in any terminal. You could write it to a file which can then be intereigate from another terminal
 
Old 05-11-2004, 02:36 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
or make that line an alias if you're planning on
using it on a regular basis ;)



Cheers,
Tink
 
Old 05-11-2004, 02:42 PM   #8
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Original Poster
Rep: Reputation: 30
ok

so lets say i saved in a file the PID that is

so now i have a file called number

pico number
returns the PID number just fine


how can i kill -WINCH /number

or how can i make a variable of that number from the text file

kinda like NUM=/number
 
Old 05-11-2004, 02:46 PM   #9
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Original Poster
Rep: Reputation: 30
i could make an alias

but how? cuz i could

alias go="kill -WINCH $PID"

but..
since i want to run that pid prosses at start the variable wont work when i log in to a term
 
Old 05-11-2004, 02:46 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by citrus
how can i kill -WINCH /number
or how can i make a variable of that number from the text file
Why don't you make
alias sc_kill="kill -WINCH `ps -ef | grep sc_trans_linux | grep -v grep | awk {'print $2'}`"
? :)

Just add that alias definition to your ~/.bashrc (or appropriate file).

No need to get a file involved, specially considering that
the PID will be different next time you run sc_tans_linux.


Cheers,
Tink
 
Old 05-11-2004, 02:51 PM   #11
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Original Poster
Rep: Reputation: 30
k i will try that
 
Old 05-11-2004, 02:55 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
almost quote from citrus
Will that alias be available in every terminal?
If it's defined in a file that the shell sources on
start, yes. It just depends on how you invoke
bash into which file you should stick it.

.bash_rc
or
.bash_profile

If in doubt, set-up a .bashrc and create a .bash_profile
that just sources .bashrc


Cheers,
Tink

Last edited by Tinkster; 05-11-2004 at 02:59 PM.
 
Old 05-11-2004, 03:07 PM   #13
citrus
Member
 
Registered: Dec 2003
Location: California
Distribution: Kubuntu 6.1
Posts: 548

Original Poster
Rep: Reputation: 30
i am unsure what my .bashrc file is named or what to name it

~/.bashrc doesn't work
i am using slackware 9.1

edit::
i will try .bash_profile
 
Old 05-11-2004, 03:26 PM   #14
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You probably want to use .bash_profile for setting up aliases and functions. It is sourced once when you log in. .bashrc is souced when everytime you start a new shell.
Look in the man page for bash for all the details. Look at which files are sourced under which circumstance. Some files may be sourced by more than one shell also. That may be something to take into consideration.
If you have different accounts you login to, examine where your system sets its functions or aliases and add it there.
 
  


Reply



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
unix cal command in an odd situation GUIPenguin General 5 10-12-2005 04:10 PM
Odd swap usage even though there is free RAM Artanicus Linux - Hardware 5 09-28-2005 02:25 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Odd results from df command avantman42 Linux - General 0 11-17-2003 10:01 AM
rm command usage big_orange Linux - General 3 11-04-2003 04:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:14 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
Open Source Consulting | Domain Registration