Process.Start(...) vs. Shell(...)

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 27 Antworten in diesem Thema. Der letzte Beitrag () ist von Snaptu.

    Process.Start(...) vs. Shell(...)

    Hi,
    also ich hab grad ein Programm am Laufen, das ich bisher immer mit Shell(...) aufgerufen habe. Dann hat mir ein weiser Mensch gesagt "Tu das nicht, nimm Process.Start(...) her!". Hab ich dann auch gemacht. Nur was mich wundert/stört, is dass ich bei Process.Start wesentlich MEHR Ressourcen an RAM/CPU verbrauche, als wenn ich das über Shell mache. Bsp: Ich starte über Shell, dann brauche ich pro Prozess von dem Programm etwa 1,7 - 1,8 MB RAM. Wenn ich das aber über Process.Start mache ( oder dim proc as Process proc.start(...)) dann brauche ich ganze 6 - 6,5MB / Prozess.... :/ ?( . Hat da wer eine Erklärung?
    Zur Info, ich lass das auch einem Terminal mit 2BG RAM und nem Intel Atom D2550 @ 1,86GHz laufen. Und ich hab ~8 Prozese offen...das Terminal wird halt ewigst langsam. Ich mein, es wird grad nur von mir verwendet -> es brauch halt im Moment keiner. Aber wenn ich mehr Prozesse laufen lassen will, hab ich Angst dass mir des Teil abschmiert, bzw das Programm nicht mehr richtig arbeitet.

    Edit: Also es geht hierbei um ein Programm, das mehrer Einträge aus einer Excel Datei/CSV liest. Die Einträge enthalten IP und Gerätebezeichnung. Auf die soll er einen "Dauerping" machen und loggen wann sie die Verbindung verlieren Hatte eh schon 2 Themen zu dem Programm offen. Evtl. erinnert sich wer dran xD. Jedenfalls sind die ~8 Prozesse nichts anders als ein Consolenprogramm, das ich 8x aufrufe.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

    Radinator schrieb:

    Process.Start(...)
    und VB6 :?:
    Was genau vergleichst Du?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    vergleichen?

    Ahh...jetz weis ich was du meinst...ich mein was is besser, bzw warum der Process.Start mehr RAM braucht als Shell, obwohl sie das selbe Programm aufrufen
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

    Radinator schrieb:

    vergleichen?
    Nein.
    Was genau vergleichst Du, wenn Du diese Ergebnisse hast:

    Radinator schrieb:

    1,7 - 1,8 MB RAM

    Radinator schrieb:

    6 - 6,5MB
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Ich habe verglichen wie viel RAM ich pro Prozess brauche, wenn ich das Programm einmal mit Shell(...) aufrufe und einmal mit Process.Start(...). Und da ist mir aufgefallen, dass ich bei Process.Start mehr RAM brauche und ich wollte wissen, warum.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Ach verdammt...falsche zeile...habs ned in VB6 sondern in VB.NET
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

    Radinator schrieb:

    sondern in VB.NET
    Dann bearbeite Deinen 1. Post und korrigiere das.
    Mit welchem Aufruf und dann wo nachgesehen kann ich Deine Werte reproduzieren?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Wenn du 2 Projekte in VS hast: Ein Konsolenprogramm und ein Windows-Forms Programm, in dem Konsolenprogramm programmierst du irgendeine Do Loop Schleife, die immer wieder was macht(aus einer Datei lesen/Aktuelle Uhrzeit reinschreiben):

    VB.NET-Quellcode

    1. Sub Main(args() as String)
    2. Using fs as new Filestream(args(1),FileMode.Create), sw as new Streamwriter(fs)
    3. Do
    4. sw.writeLine(args(1))
    5. Loop
    6. End Using
    7. End Sub

    In das W-F Programm schreibst du den Aufruf:

    VB.NET-Quellcode

    1. For i = 1 to 8
    2. Shell(konsolenprogramm("C:\" & i & ".txt" & " " & Now))
    3. next i

    Wenn du einmal das mit Shell(...) machst, dann braucht jeder Prozess weniger RAM, als wenn man das mit Proces.Start(...) macht

    VB.NET-Quellcode

    1. For i = 1 to 8
    2. Process.Start(konsolenprogramm, "C:\" & i & ".txt" & " " & Now)
    3. next i
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    @Radinator AHa.
    Shell ruft auf und ist feddich.
    Process erstellt eine Instanz für den jeweiligen Prozess, über die Du mit dem Prozess kommunizieren kannst usw., sieh Dir mal die Process-Klasse in der MSDN an.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Ah ok danke.
    Hab da aber zu
    erstellt eine Instanz für den jeweiligen Prozess, über die Du mit dem Prozess kommunizieren kannst
    noch ne Frage:
    Ich hab da ja in dem Modul eine Do Loop -> Endlosschleife drinnen. Problem is aber, dass mir manchmal der "Satz" den der sw schreibt einfach abgeschnitten wird, wenn ich dem Prozess mit

    VB.NET-Quellcode

    1. Dim pList() as Process = Process.GetProcesses
    2. For each p in pList
    3. if p.toString.Contains("sender") then
    4. p.kill
    5. end if
    6. Next

    beende. Kann ich den auch "sanft" beenden, sprich sagen: Mach den Durchlauf noch und hör dann auf?( Bzw so in die Richtung Console_Closing Event) Oder geht des nur auf die harte Tour mit p.Kill?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Ich weiß jetzt nicht wie stark p.kill ist (ein Task-Manager / herunterfahren bekommt ja noch alles gekillt ;)), jedoch wäre es ja vielleicht möglich, deine Schleife in nen Thread zu packen, die eine Variable abfragt, die anfangs auf true steht. Wird das closing event gefeuert, stellst du diese variable auf false, und wartest so lange, bis der thread fertig ist.
    Dann müsste ich doch aber den Modul-Prozess bzw das Modul selbst doch in meinem Oberprogramm integriert haben oder?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    mMn ist ein sanftes Beenden einer Konsole nach fertigstellung der Arbeit per "exit" befehl möglich.

    Edit: Ich sehe gerade auf MSDN steht es empfiehlt sich wenn die Konsole mit process.start() gestartet wurde dann soll man nachher auch mit process.Close() das Process-Objekt schließen.
    Wer fragt, ist ein Narr für eine Minute. Wer nicht fragt, ist ein Narr sein Leben lang.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Snaptu“ ()

    Ja das hab ich mir auch schon gedacht, aber ich will ja von außen auf den Prozess zugreifen, sprich die Do Loop Schleife beenden
    Zur Info, so ungefähr siet mein Code aus:

    VB.NET-Quellcode

    1. Sub Main(args() As String)
    2. Dim ip As String = args(0), pfad As String = args(1), geraet As String = args(2)
    3. Dim txt As String = ""
    4. Dim reply As String = ""
    5. Dim time As String = ""
    6. Using fs As New FileStream(pfad, FileMode.OpenOrCreate), sw As New StreamWriter(fs), ping As New Ping
    7. Do
    8. With ping.Send(ip)
    9. reply = .Status.ToString
    10. time = .RoundtripTime
    11. End With
    12. txt = Format(Now, "dd.MM.yyyy hh:mm:ss:fff") & Format(time, "{0,8}") & " " & reply & ";" & vbCrLf
    13. sw.Write(txt)
    14. Console.Write(txt)
    15. sw.Flush()
    16. Loop
    17. sw.Close()
    18. Console.ReadKey()
    19. End Using
    20. End Sub
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    ich bin da noch nicht so bewandert aber eine Do While Schleife müsste dein Problem doch lösen denn eine Ausstiegsbedingung hast du ja oder du gibts nach dem Loop ein Until/While hin und schreibst darunter die Ausstiegsbedingung.
    Irgendwie verwirrt mich dein Code auch denn alles was du da machst kannst du in einer Forms Anwendung alleine auch machen?
    Wer fragt, ist ein Narr für eine Minute. Wer nicht fragt, ist ein Narr sein Leben lang.
    Und die wäre?

    Ich hab deswegen ja die Do Loop verwendet, weil ich ja einen Endlosping machen wollte -> analog zum cmd ping xxx.xxx.xxx.xxx -t und das kann ich nur mit einer Do Loop
    In meinem Oberprogramm hab ich einen Countdown und einen Button drinnen, wenn entweder der Countdown auf 0 ist oder der Button betätigt wird, dann wird eine Sub aufgerufen die alle Ping Prozesse killt

    VB.NET-Quellcode

    1. Private Sub killSender()
    2. Dim pList as Process = Process.GetProcesses
    3. For each p in pList
    4. If p.toString.Contains("sender") Then
    5. p.Kill()
    6. End If
    7. Next
    8. End Sub


    Edit: Ich hab deswegen die Ping-Geschichte ausgelagter, weil ich nicht wusste, wie ich mehr als 1 von dem Ping Prozess starte
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Oben schreibst du, du willst die schleife beenden jetzt ist sie Endlos? Also was solls jetzt sein? Ausserdem läuft sie ja solange die Bedingung nicht erfüllt ist ;)
    Ich glaube noch immer das für dein vorhaben nicht 8 Konsolenanwendungen notwendig sind sondern alles mit der Forms Anwendung gehen würde.
    Wer fragt, ist ein Narr für eine Minute. Wer nicht fragt, ist ein Narr sein Leben lang.
    Threads? So mit System.Threading.Thread?

    Edit: @Snaptu: Also folgendes ist mein Plan: Ich soll eine Liste von IPs gleichzeitig anpingen und loggen, ob sie einen Ausfall (timedout) haben oder nicht. Das ganze soll wie gesagt gleichzeitig, parallel passieren, d.h. ich will das nicht mit einer for schleife machen, wo erst die eine gepingt wird, dann die andere und dann die dritte und so weiter (habs auch schon ma mit ner parallel.foreach probiert, da ping er die IPs zwar "parallel" allerdings schreibt er mit die ergebnisse auch querbet in die Loggingdatei rein und das will ich ned/brauch ich ned). Ich habs dewegen "ausgelager" weil ich nicht weis, wie ich es anders machen soll. Hatte es auch schon versucht, dass ich in das Projekt ein Modul eingefügt und wollte es starten...hat nicht wirklich gefunzt.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell