silex
1
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:
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
that depends on the maximum number allowed for a PID and it varies from system to system
silex
3
I'm looking for a PIDMAX or something like this, but I can't find anything. This is my system:
ASASTR:include> uname -a
OSF1 CLHASASTR V5.1 2650 alpha
Thanks again
cannot you just get the whole column instead of relying on character ranges?
something like:
ps -ef | grep 'in/Alime' | cut -d ' ' -f1
silex
5
yes, the whole column would be great. I have tried to get only the second column
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
ps -ef | grep 'in/Alime' | cut -d ' ' -f 2
cut's field delimiter is 'tab' by default......
silex
7
these are my outputs:
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.
ps -ef | grep "bin/Alime" | grep -v grep | awk '{print $2}'
ps -ef | awk '/bin\/Alime/{print $2}'
yep, no need to all the greppin' brouhaha
silex
12
I have found this PID_MAX:
(./usr/sys/include/sys/limits.h)
#define PID_MAX INT_MAX /* max value for process ID */
and INT_MAX is defined as:
(./arch/alpha/machlimits.h)
#define INT_MAX 2147483647 /* max value for an int */
2147483647 --> 10 characters
Thank you very much to all of you for your time
Oops ! The awk option is much better ! thanks again !!
ps -ef | grep your_process | grep -v grep | tr -s " " | cut -f2
probably doesn't matter. to reduce redundant use of grep -v grep, you could use awk
ps -ef | awk '/process/{print $2}'
Ghostdog , that was a good piece, But at times feel I can type "grep -v grep " much faster than trying to escape the /'s when using awk.
for an example , to grep the '/etc/init' , I feel that the second way is pretty easier and faster to type
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jan 14 - 40:54 /etc/init
team$ ps -ef | awk '/\/etc\/init/ { print $0 }'
root 1 0 0 Jan 14 - 40:53 /etc/init
team$
team$ ps -ef | grep '/etc/init' | grep -v grep
root 1 0 0 Jan 14 - 40:55 /etc/init
team$