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.

How to check same process running 10 times?

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 11-10-2017   -   Original Discussion by Kalia
Kalia's Unix or Linux Image
Kalia Kalia is offline
Registered User
Join Date: Jun 2017
Last Activity: 20 January 2018, 9:53 AM EST
Posts: 36
Thanks: 9
Thanked 0 Times in 0 Posts
Thanks a lot for ur quick respond Am runing below script passing 1 because no duplicate job runing now it giving correct output-AIX operating system

my question::Will it work if runing more then 10 time or will it compaire please confirm

awk '++s[$2]==10'

jobs=$(ps -u pintu -o pid= -o args=| awk '++s[$2]==1')
if [[ -n "$jobs" ]]
  printf "jobs runing longtime:\n%s\n" "$jobs"
  exit 1

see the below output also

jobs runing longtime:
 2362 /usr/bin/gnome-keyring-daemon --daemonize --login
 2371 gnome-session
 2380 dbus-launch --sh-syntax --exit-with-session
 2381 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
 2399 /usr/libexec/gconfd-2
 2406 /usr/libexec/gnome-settings-daemon
 2408 seahorse-daemon
 2415 /usr/libexec/gvfsd
 2423 metacity
 2434 /usr/bin/pulseaudio --start --log-target=syslog
 2435 gnome-panel
 2440 /usr/libexec/pulse/gconf-helper
 2441 nautilus
 2443 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=18
 2453 /usr/libexec/gvfs-gdu-volume-monitor
 2454 /usr/libexec/wnck-applet --oaf-activate-iid=OAFIID:GNOME_Wncklet_Factory --oaf-ior-fd=18
 2455 /usr/libexec/trashapplet --oaf-activate-iid=OAFIID:GNOME_Panel_TrashApplet_Factory --oaf-ior-fd=24
 2459 /usr/lib/vmware-tools/sbin32/vmtoolsd -n vmusr --blockFd 3
 2467 gpk-update-icon
 2470 gnome-power-manager
 2474 gnome-volume-control-applet
 2476 bluetooth-applet
 2480 /usr/sbin/restorecond -u
 2482 /usr/libexec/polkit-gnome-authentication-agent-1
 2485 python /usr/share/system-config-printer/applet.py
 2486 /usr/libexec/gdu-notification-daemon
 2489 nm-applet --sm-disable
 2494 /usr/libexec/gvfs-afc-volume-monitor
 2498 /usr/libexec/gvfsd-trash --spawner :1.7 /org/gtk/gvfs/exec_spaw/0
 2502 /usr/libexec/gvfs-gphoto2-volume-monitor
 2509 gnome-screensaver
 2518 /usr/bin/gnote --panel-applet --oaf-activate-iid=OAFIID:GnoteApplet_Factory --oaf-ior-fd=23
 2519 /usr/libexec/clock-applet --oaf-activate-iid=OAFIID:GNOME_ClockApplet_Factory --oaf-ior-fd=29
 2520 /usr/libexec/notification-area-applet --oaf-activate-iid=OAFIID:GNOME_NotificationAreaApplet_Factory --oaf-ior-fd=39
 2521 /usr/libexec/gdm-user-switch-applet --oaf-activate-iid=OAFIID:GNOME_FastUserSwitchApplet_Factory --oaf-ior-fd=35
 2562 /usr/libexec/gvfsd-burn --spawner :1.7 /org/gtk/gvfs/exec_spaw/1
 2569 /usr/libexec/gvfsd-metadata
 2575 /usr/bin/gnome-terminal -x /bin/sh -c cd '/home/pintu/Desktop' && exec $SHELL -l
 2576 gnome-pty-helper
 2577 /bin/bash -l
 2843 sh t2.sh
 2845 ps -u pintu -o pid= -o args=
 2846 awk ++s[$2]==1

Sponsored Links
Old Unix and Linux 11-15-2017   -   Original Discussion by Kalia
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Join Date: May 2012
Last Activity: 16 June 2018, 4:11 PM EDT
Location: Simplicity
Posts: 4,117
Thanks: 357
Thanked 1,400 Times in 1,258 Posts

awk '++s[$2]==10'

lists the 10th occurrence of column#2, and if there are more than 10 it will not wipe a previously printed one Linux
You can search for certain strings through the whole line like this

awk '(index($0, "a.ksh") || index($0, "d.ksh") && ++s[$2]==10'

and this should work with the args.
Regarding "jobs running longtime", perhaps etime (elapsed time) is more interesting:

ps -e -o pid= -o etime= -o args=

And now your task is to have the postprocessor (awk) compute a comparible number from the etime column.
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How a process can check if a particular process is running on different machine? saurabhnsit2001 UNIX for Dummies Questions & Answers 2 06-02-2012 11:14 PM
need to check if the process is running shifahim Shell Programming and Scripting 8 08-18-2011 10:17 PM
How do I check if a process is running in C cprogdude Programming 1 10-12-2010 05:01 AM
How to check if process is running? ladyAnne UNIX and Linux Applications 5 05-01-2010 01:20 AM
Check if Process is running Raynon Shell Programming and Scripting 3 01-08-2010 02:03 AM

All times are GMT -4. The time now is 01:49 AM.