Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

unix and linux commands - unix shell scripting

PID length

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
silex's Unix or Linux Image
silex silex is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 14 March 2011, 11:56 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
PID length

Does somebody know how many characters can have a PID as maximum?

I'm trying to get the PID of another process running in the same machine. I'm doing this:



Code:
ps -ef | grep "bin/Alime" | grep -v grep  | cut -c10-16

but I don't know if I 'll have enough with six chars. Which is the max value that it can take?

thanks in advance
Sponsored Links
    #2  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
matrixmadhan's Unix or Linux Image
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 10 January 2017, 8:10 AM EST
Location: classification algos
Posts: 3,215
Thanks: 19
Thanked 31 Times in 28 Posts
that depends on the maximum number allowed for a PID and it varies from system to system
Sponsored Links
    #3  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
silex's Unix or Linux Image
silex silex is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 14 March 2011, 11:56 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I'm looking for a PIDMAX or something like this, but I can't find anything. This is my system:


Code:
ASASTR:include> uname -a
OSF1 CLHASASTR V5.1 2650 alpha

Thanks again
    #4  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 13 January 2018, 6:50 AM EST
Location: Foxborough, MA
Posts: 8,204
Thanks: 231
Thanked 786 Times in 733 Posts
cannot you just get the whole column instead of relying on character ranges?
something like:


Code:
ps -ef | grep '[b]in/Alime' | cut -d ' ' -f1

Sponsored Links
    #5  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
silex's Unix or Linux Image
silex silex is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 14 March 2011, 11:56 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
yes, the whole column would be great. I have tried to get only the second column



Code:
 ps -ef | grep "bin/Alime" | grep -v grep  | cut -f 2

but it shows the whole line again. I don't know why, maybe the command is not correct.

thanks
Sponsored Links
    #6  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 13 January 2018, 6:50 AM EST
Location: Foxborough, MA
Posts: 8,204
Thanks: 231
Thanked 786 Times in 733 Posts


Code:
ps -ef | grep '[b]in/Alime' | cut -d ' ' -f 2

cut's field delimiter is 'tab' by default......
Sponsored Links
    #7  
Old Unix and Linux 12-20-2007   -   Original Discussion by silex
silex's Unix or Linux Image
silex silex is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 14 March 2011, 11:56 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
these are my outputs:



Code:
ASASTR:clh> ps -ef | grep "bin/Alime" | grep -v grep
clh      221867 217065  0.0 11:34:01 pts/4        0:00.08 /usr/local/clh/ALPHA/oasys/bin/AlimentaLookAhead

ASASTR:clh> ps -ef | grep "bin/Alime" | grep -v grep  | cut -c10-16
221867

ASASTR:clh> ps -ef | grep "bin/Alime" | grep -v grep  | cut -d ' ' -f1
clh

ASASTR:clh>  ps -ef | grep "bin/Alime" | grep -v grep  | cut -d ' ' -f2

ASASTR:clh>  ps -ef | grep "bin/Alime" | grep -v grep  | cut -f2
clh      221867 217065  0.0 11:34:01 pts/4        0:00.08 /usr/local/clh/ALPHA/oasys/bin/AlimentaLookAhead

asking for the first column (-f1) i get the username, but asking for the second (-f2) i get the whole line.
Thanks.
Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Flat file-make field length equal to header length sonali.s.more Shell Programming and Scripting 5 03-28-2012 09:39 AM
What the command to find out the record length of a fixed length file? tranq01 UNIX for Dummies Questions & Answers 9 12-04-2008 04:04 PM
Sed working on lines of small length and not large length thanuman UNIX for Dummies Questions & Answers 3 04-15-2005 07:12 AM
creating a fixed length output from a variable length input r1500 Shell Programming and Scripting 2 12-03-2003 01:09 PM



All times are GMT -4. The time now is 09:26 AM.