7

I have to check numbers of scripts currently executing in Linux based on which I have to decide whether to run the script again or not. The issue is that the classpath is too long so while executing ps -ef I'm not getting the full path, only part of it.

For example:

00:04:43 /usr/java/jdk1.6/bin/java -classpath /usr/share/groovy-2.0.5/lib/groovy-2.0.5.jar -Dscript.name=/usr/share/groovy-2.0.5/bin/groovy -Dprogram.name=groovy -Dgroovy.starter.conf=/usr/share/groovy-2.0.5/conf/groovy-starter.conf -Dgroovy.home=/usr/share/groovy-2.0.5 -Dtools.jar=/usr/java/jdk1.6/lib/tools.jar org.codehaus.groovy.tools.GroovyStarter --main groovy.ui.GroovyMain --conf /usr/share/groovy-2.0.5/conf/groovy-starter.conf --classpath /usr/share/groovy-2.0.5/lib_novabill/mail.jar:/app/kenanfx/site_specific/apits/javaclient/java:/app/kenanfx/bsdm_site/config:/app/kenanfx/FXSecServer-6.0.20120520/server/config:/app/kenanfx/site_specific/apits/javaclient/java/aimw.jar:/app/kenanfx/site_specific/apits/javaclient/java/aimwDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/aruba.jar:/app/kenanfx/site_specific/apits/javaclient/java/arubaDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/bali.jar:/app/kenanfx/site_specific/apits/javaclient/java/bali_2tier.jar:/app/kenanfx/site_specific/apits/javaclient/java/baliDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/batch.jar:/app/kenanfx/site_specific/apits/javaclient/java/batchDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/cit.jar:/app/kenanfx/site_specific/apits/javaclient/java/citDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/commons-httpclient-2.0-alpha3.jar:/app/kenanfx/site_specific/apits/javaclient/java/commons-logging-1.0.3.jar:/app/kenanfx/site_specific/apits/javaclient/java/configurator.jar:/app/kenanfx/site_specific/apits/javaclient/java/configuratorDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/ContentCatalog.jar:/app/kenanfx/site_specific/apits/javaclient/java/ContentCatalogDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/customerudt.jar:/app/kenanfx/site_specific/apits/javaclient/java/customerudtDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/ducm.jar:/app/kenanfx/site_specific/apits/javaclient/java/ducmDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/FXSecBPRules.jar:/app/kenanfx/site_specific/apits/javaclient/java/FXSecFwkClient.jar:/app/kenanfx/site_specific/apits/javaclient/java/FXSecFwkDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/inventory.jar:/app/kenanfx/site_specific/apits/javaclient/java/inventoryDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/javaee-api-5.0-2.jar:/app/kenanfx/site_specific/apits/javaclient/java/jaxb-api.jar:/app/kenanfx/site_specific/apits/javaclient/java/jaxb-impl.jar:/app/kenanfx/site_specific/apits/javaclient/java/jaxb-libs.jar:/app/kenanfx/site_specific/apits/javaclient/java/jax-qname.jar:/app/kenanfx/site_specific/apits/javaclient/java/JNITuxedo.jar:/app/kenanfx/site_specific/apits/javaclient/java/JNITuxedo_2tier.jar:/app/kenanfx/site_specific/apits/javaclient/java/namespace.jar:/app/kenanfx/site_specific/apits/javaclient/java/ordering.jar:/app/kenanfx/site_specific/apits/javaclient/java/orderingDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/PayPerView.jar:/app/kenanfx/site_specific/apits/javaclient/java/PayPerViewDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/relaxngDatatype.jar:/app/kenanfx/site_specific/apits/javaclient/java/serviceability.jar:/app/kenanfx/site_specific/apits/javaclient/java/serviceabilityDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/sfq.jar:/app/kenanfx/site_specific/apits/javaclient/java/sfqDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/shieldware.jar:/app/kenanfx/site_specific/apits/javaclient/java/tuxedo.jar:/app/kenanfx/site_specific/apits/javaclient/java/udt.jar:/app/kenanfx/site_specific/apits/javaclient/java/udtDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/utility.jar:/app/kenanfx/site_specific/apits/javaclient/java/utilityDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/workflow.jar:/app/kenanfx/site_specific/apits/javaclient/java/workflowDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/workpoint.jar:/app/kenanfx/site_specific/apits/javaclient/java/workpointDocs.jar:/app/kenanfx/site_specific/apits/javaclient/java/xsdlib.jar:/app/

So how can I retrieve the required info?

Zanna
  • 70,465
  • ps aux or pgrep -f should help – Sylvain Pineau Apr 21 '16 at 07:46
  • @SylvainPineau @ Eric Carvalho @ heemayl, I have read the edit history of the post, and maybe marking it as a duplicate to the given question made sense then, but it absolutely does not now. The linked thread deals with issues of process filtering by the user, while this one is about the actual content of the output being cut off. Furthermore this thread is the first one found on this issue on a search engine, which means it's a heavily seen thread and having it as a duplicate prevents further discussion and adding info which thwarts the purpose of SO. Please remove the duplicate marker. – Atralb Jan 25 '23 at 11:45

2 Answers2

9

How to get the full lines in the output

To get the full output, you can add ww after the command:

ps -ef ww

Then, the lines in the output will not be cut off.
I often use this in scripts to make sure the output fully matches the running script.

Example:

from ps -ef:

jacob    11173  5876  0 apr19 ?        00:00:08 /usr/bin/unity-scope-

while ps -ef ww sais:

jacob    11173  5876  0 apr19 ?        Sl     0:08 /usr/bin/unity-scope-loader applications/applications.scope applications/scopes.scope commands.scope
Jacob Vlijm
  • 83,767
-1

Use pgrep. For example, pgrep java -a.

A test with Google Chrome processes:

$ pgrep chrome -a 
3572 /opt/google/chrome/chrome       
3584 /opt/google/chrome/chrome-sandbox /opt/google/chrome/chrome --type=zygote
3586 /opt/google/chrome/chrome --type=zygote
3588 /opt/google/chrome/chrome-sandbox /opt/google/chrome/nacl_helper
3592 /opt/google/chrome/chrome --type=zygote
3689 /opt/google/chrome/chrome --type=gpu-process --channel=3572.0.1702347006 --window-depth=24 --supports-dual-gpus=false --gpu-driver-bug-workarounds=4,25,33,36,48,53,64,66 --disable-accelerated-video-decode --gpu-vendor-id=0x10de --gpu-device-id=0x11a1 --gpu-driver-vendor=NVIDIA --gpu-driver-version=364.16 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
3739 /opt/google/chrome/chrome --type=gpu-broker                                                                                                                                                                                                                                                                                                                
3759 /opt/google/chrome/chrome --type=renderer --enable-features=LinuxObsoleteSystemIsEndOfTheLine<LinuxObsoleteSystemIsEndOfTheLine,WebFontsIntervention<WebFontsIntervention --lang=en-GB --force-fieldtrials=AppBannerTriggering/Aggressive/AutofillProfileOrderByFrecency/Enabled/BrotliEncoding/Default/CaptivePortalInterstitial/Enabled/*ChildAccountDetection/Disabled/*ClientSideDetectionModel/Model0/*CrossDevicePromo/28DaySingleProfile/*DataReductionProxyConfigService/Enabled/*ExtensionActionRedesign/Enabled/*ExtensionDeveloperModeWarning/Default/*GFE/Default/InstanceID/Enabled/LinuxObsoleteSystemIsEndOfTheLine/EndOfLine/MaterialDesignDownloads/Enabled/*OmniboxBundledExperimentV1/Unused_2/PasswordBranding/Disabled/*PasswordGeneration/Disabled/*QUIC/EnabledNoId/ReportCertificateErrors/ShowAndPossiblySend/*ResourcePriorities/Launch50pct_11011_1_1_10/SHA1IdentityUIWarning/Enabled/SHA1ToolbarUIJanuary2016/Warning/SHA1ToolbarUIJanuary2017/Error/SSLCommonNameMismatchHandling/Disabled/*SafeBrowsingIncidentReportingService/Default/SafeBrowsingIncidentReportingServiceFeatures/Default/SafeBrowsingUnverifiedDownloads/DisableByParameterMostSbTypes2/SafeBrowsingUpdateFrequency/Default/*UMA-Population-Restrict/normal/*UMA-Uniformity-Trial-1-Percent/group_32/*UMA-Uniformity-Trial-10-Percent/group_08/*UMA-Uniformity-Trial-100-Percent/group_01/*UMA-Uniformity-Trial-20-Percent/group_04/*UMA-Uniformity-Trial-5-Percent/group_13/*UMA-Uniformity-Trial-50-Percent/group_01/*UseDelayAgnosticAEC/DefaultEnabled/WebFontsIntervention/Enabled/WebRTC-LocalIPPermissionCheck/Enabled/WebRTC-PeerConnectionDTLS1.2/Enabled/ --extension-process --enable-webrtc-hw-h264-encoding --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --blink-settings=fetchDeferLateScripts=true,fetchIncreaseFontPriority=true,fetchIncreasePriorities=true --enable-suggestions-with-substring-match --enable-pinch --num-raster-threads=4 --content-image-texture-target
3890 /opt/google/chrome/chrome --type=renderer --enable-features=LinuxObsoleteSystemIsEndOfTheLine<LinuxObsoleteSystemIsEndOfTheLine,WebFontsIntervention<WebFontsIntervention --lang=en-GB --force-fieldtrials=AppBannerTriggering/Aggressive/AutofillProfileOrderByFrecency/Enabled/BrotliEncoding/Default/CaptivePortalInterstitial/Enabled/*ChildAccountDetection/Disabled/*ClientSideDetectionModel/Model0/*CrossDevicePromo/28DaySingleProfile/*DataReductionProxyConfigService/Enabled/*ExtensionActionRedesign/Enabled/*ExtensionDeveloperModeWarning/Default/*GFE/Default/InstanceID/Enabled/LinuxObsoleteSystemIsEndOfTheLine/EndOfLine/MaterialDesignDownloads/Enabled/*OmniboxBundledExperimentV1/Unused_2/PasswordBranding/Disabled/*PasswordGeneration/Disabled/*QUIC/EnabledNoId/ReportCertificateErrors/ShowAndPossiblySend/*ResourcePriorities/Launch50pct_11011_1_1_10/SHA1IdentityUIWarning/Enabled/SHA1ToolbarUIJanuary2016/Warning/SHA1ToolbarUIJanuary2017/Error/SSLCommonNameMismatchHandling/Disabled/*SafeBrowsingIncidentReportingService/Default/SafeBrowsingIncidentReportingServiceFeatures/Default/SafeBrowsingUnverifiedDownloads/DisableByParameterMostSbTypes2/SafeBrowsingUpdateFrequency/Default/*UMA-Population-Restrict/normal/*UMA-Uniformity-Trial-1-Percent/group_32/*UMA-Uniformity-Trial-10-Percent/group_08/*UMA-Uniformity-Trial-100-Percent/group_01/*UMA-Uniformity-Trial-20-Percent/group_04/*UMA-Uniformity-Trial-5-Percent/group_13/*UMA-Uniformity-Trial-50-Percent/group_01/*UseDelayAgnosticAEC/DefaultEnabled/*WebFontsIntervention/Enabled/WebRTC-LocalIPPermissionCheck/Enabled/WebRTC-PeerConnectionDTLS1.2/Enabled/ --extension-process --enable-webrtc-hw-h264-encoding --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --blink-settings=fetchDeferLateScripts=true,fetchIncreaseFontPriority=true,fetchIncreasePriorities=true --enable-suggestions-with-substring-match --enable-pinch --num-raster-threads=4 --content-image-texture-targe

Considering the length of the the last two lines, I don't think it will have a problem.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 1
    This is absolutely not an answer to the question. pgrep is a completely other tool that is merely a shortcut to a very narrow usecase among everything that ps does. Indeed, this does not solve the issue of a cropped output from an arbitrary ps command in any way. – Atralb Jan 25 '23 at 11:25
  • @Atralb I don't know which pgrep you use, but it's filtering abilities are fairly broad, and can do things that ps by itself can't. I think this is a good enough solution to OP's use case, I don't really care about your unstated use case. If you have a different use case, you should post a new question. – muru Jan 25 '23 at 12:30