Script started on Mon Dec 2 12:28:12 2024 mweeks@air:unix_ch13$ echo 5150 5150 mweeks@air:unix_ch13$ cat myexec.c #include #include // for fork, sleep #include // for wait int main () { printf ("I'm process %d and I'm about to exec an ls -l\n", getpid ()); // NULL indicates last command. There could be more than 1 execl ("/bin/ls", "ls", "-l", NULL); /* Execute ls */ printf ("This line should never be executed\n"); return 0; } mweeks@air:unix_ch13$ sftp snowball.cs.gsu.edu mweeks@snowball.cs.gsu.edu's password: Connected to snowball.cs.gsu.edu. sftp> put myexec.c Uploading myexec.c to /home/mweeks/myexec.c myexec.c 100% 366 59.5KB/s 00:00 sftp> quit mweeks@air:unix_ch13$ ^ftp^sh^ ssh snowball.cs.gsu.edu mweeks@snowball.cs.gsu.edu's password: Permission denied, please try again. mweeks@snowball.cs.gsu.edu's password: Last failed login: Mon Dec 2 13:15:48 EST 2024 from 131.96.221.178 on ssh:notty There was 1 failed login attempt since the last successful login. Last login: Thu Nov 21 11:16:12 2024 from c-24-99-154-26.hsd1.ga.comcast.net + | GSU Computer Science | Instructional Server | SNOWBALL.cs.gsu.edu + [mweeks@gsuad.gsu.edu@snowball ~]$ ls -l myexec* -rw-r--r--. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 366 Dec 2 13:15 myexec.c [mweeks@gsuad.gsu.edu@snowball ~]$ gcc myexec.c [mweeks@gsuad.gsu.edu@snowball ~]$ ./a.out I'm process 636 and I'm about to exec an ls -l total 160 -rwxrwxr-x. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 8512 Dec 2 13:16 a.out -rwxrwxr-x. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 8360 Sep 9 13:23 bad_example.c -rw-rw-r--. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 0 Sep 4 13:29 donotdothis -rw-rw-r--. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 39 Aug 26 13:18 example1 -rw-r--r--. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 49 Aug 26 13:34 example2 [ some lines deleted ] drwxrwxr-x. 2 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 4096 Nov 11 13:38 unix_ch5 [mweeks@gsuad.gsu.edu@snowball ~]$ man exec [mweeks@gsuad.gsu.edu@snowball ~]$ exit logout Connection to snowball.cs.gsu.edu closed. mweeks@air:unix_ch13$ cat mychdir.c #include #include // exit() #include // for fork, sleep #include // for wait int main () { /* Display current working directory */ system ("pwd"); /* Change working directory to root directory */ chdir ("/"); /* Display new working directory */ system ("pwd"); chdir ("/Users/mweeks"); /* Change again */ system ("pwd"); /* Display again */ return 0; } mweeks@air:unix_ch13$ gcc mychdir.c mweeks@air:unix_ch13$ ./a.out /Users/mweeks/Desktop/csc3320/programs/unix_ch13 / /Users/mweeks mweeks@air:unix_ch13$ pwd /Users/mweeks/Desktop/csc3320/programs/unix_ch13 mweeks@air:unix_ch13$ cat talk.c // Linux for Programmers and Users, Glass/Ables, page 503 #include #include #include #include #include #define READ 0 /* The index of the read end of the pipe */ #define WRITE 1 /* The index of the write end of the pipe */ char* phrase = "Stuff this in your pipe and smoke it"; int main() { int fd [2], bytesRead; char message [100]; /* Parent process' message buffer */ pipe (fd); /*Create an unnamed pipe */ if (fork () == 0) /* Child, writer */ { close(fd[READ]); /* Close unused end */ write (fd[WRITE],phrase, strlen (phrase) + 1); /* include NULL*/ close (fd[WRITE]); /* Close used end */ } else /* Parent, reader*/ { close (fd[WRITE]); /* Close unused end */ bytesRead = read (fd[READ], message, 100); printf ("Read %d bytes: %s\n", bytesRead, message); /* Send */ close (fd[READ]); /* Close used end */ } return 0; } mweeks@air:unix_ch13$ gcc talk.c mweeks@air:unix_ch13$ ./a.out Read 37 bytes: Stuff this in your pipe and smoke it mweeks@air:unix_ch13$ curl "https://www.man7.org/linux/man-pages/man3/exec.3.html" > exec_man_page.html % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 19421 100 19421 0 0 18345 0 0:00:01 0:00:01 --:--:-- 18356 mweeks@air:unix_ch13$ more exec_man_page.html exec(3) - Linux manual page

exec(3) — Linux manual page

[ some lines deleted ] mweeks@air:unix_ch13$ cat zombie.c // This is from the // Unix book by Glass and Ables, page 478 // I added a few lines. -MCW #include #include // exit() #include // fork() int main () { int pid; pid = fork (); /* Duplicate */ /* Branch based on return value from fork () */ if (pid != 0) { /* Never terminate, never execute a wait () */ while (1) sleep (1000); } else { exit (42); /* Exit with a silly number */ } return 0; } mweeks@air:unix_ch13$ gcc zombie.c mweeks@air:unix_ch13$ ./a.out ^C mweeks@air:unix_ch13$ ps PID TTY TIME CMD 23213 ttys000 0:06.08 -bash 20937 ttys001 0:00.05 script Dec2_2024.log 52960 ttys001 0:04.83 -bash 57730 ttys002 0:01.12 -bash 21990 ttys003 0:02.93 -bash 20938 ttys004 0:00.05 /bin/bash -i 87215 ttys005 0:03.93 -bash mweeks@air:unix_ch13$ !sftp sftp snowball.cs.gsu.edu mweeks@snowball.cs.gsu.edu's password: Connected to snowball.cs.gsu.edu. sftp> put zombie.c Uploading zombie.c to /home/mweeks/zombie.c zombie.c 100% 463 82.3KB/s 00:00 sftp> quit mweeks@air:unix_ch13$ !ssh ssh snowball.cs.gsu.edu mweeks@snowball.cs.gsu.edu's password: Permission denied, please try again. mweeks@snowball.cs.gsu.edu's password: Last failed login: Mon Dec 2 13:32:00 EST 2024 from 131.96.221.178 on ssh:notty There was 1 failed login attempt since the last successful login. Last login: Mon Dec 2 13:15:54 2024 from 131.96.221.178 + | GSU Computer Science | Instructional Server | SNOWBALL.cs.gsu.edu + [mweeks@gsuad.gsu.edu@snowball ~]$ gcc zombie.c [mweeks@gsuad.gsu.edu@snowball ~]$ ./a.out ^C [mweeks@gsuad.gsu.edu@snowball ~]$ ps PID TTY TIME CMD 2615 pts/7 00:00:00 bash 2717 pts/7 00:00:00 ps [mweeks@gsuad.gsu.edu@snowball ~]$ ps -e PID TTY TIME CMD 1 ? 00:36:14 systemd 2 ? 00:00:05 kthreadd 4 ? 00:00:00 kworker/0:0H 6 ? 00:00:15 ksoftirqd/0 7 ? 00:00:12 migration/0 [ some lines deleted ] 32584 pts/30 00:00:00 bash [mweeks@gsuad.gsu.edu@snowball ~]$ ps -eU mweeks PID TTY TIME CMD 1 ? 00:36:14 systemd 2 ? 00:00:05 kthreadd 4 ? 00:00:00 kworker/0:0H 6 ? 00:00:15 ksoftirqd/0 7 ? 00:00:12 migration/0 [ some lines deleted ] [mweeks@gsuad.gsu.edu@snowball ~]$ ps -U mweeks PID TTY TIME CMD 2614 ? 00:00:00 sshd 2615 pts/7 00:00:00 bash 2743 pts/7 00:00:00 ps [mweeks@gsuad.gsu.edu@snowball ~]$ ./a.out ^Z [1]+ Stopped ./a.out [mweeks@gsuad.gsu.edu@snowball ~]$ bg [1]+ ./a.out & [mweeks@gsuad.gsu.edu@snowball ~]$ ps -U mweeks PID TTY TIME CMD 2614 ? 00:00:00 sshd 2615 pts/7 00:00:00 bash 2759 pts/7 00:00:00 a.out 2760 pts/7 00:00:00 a.out 2767 pts/7 00:00:00 ps [mweeks@gsuad.gsu.edu@snowball ~]$ ps -U mweeks PID TTY TIME CMD 2614 ? 00:00:00 sshd 2615 pts/7 00:00:00 bash 2759 pts/7 00:00:00 a.out 2760 pts/7 00:00:00 a.out 2776 pts/7 00:00:00 ps [mweeks@gsuad.gsu.edu@snowball ~]$ fg ./a.out ^C [mweeks@gsuad.gsu.edu@snowball ~]$ ps -U mweeks PID TTY TIME CMD 2614 ? 00:00:00 sshd 2615 pts/7 00:00:00 bash 2783 pts/7 00:00:00 ps [mweeks@gsuad.gsu.edu@snowball ~]$ ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 194644 5476 ? Ss Sep13 36:14 /usr/lib/system root 2 0.0 0.0 0 0 ? S Sep13 0:05 [kthreadd] root 4 0.0 0.0 0 0 ? S< Sep13 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S Sep13 0:15 [ksoftirqd/0] root 7 0.0 0.0 0 0 ? S Sep13 0:12 [migration/0] [ some lines deleted ] mweeks@+ 2614 0.0 0.0 195824 2708 ? S 13:32 0:00 sshd: mweeks@gs mweeks@+ 2615 0.0 0.0 126912 2928 pts/7 Ss 13:32 0:00 -bash mweeks@+ 2861 0.0 0.0 168468 2248 pts/7 R+ 13:34 0:00 ps -aux [ some lines deleted ] [mweeks@gsuad.gsu.edu@snowball ~]$ top top - 13:36:18 up 79 days, 23:03, 25 users, load average: 1.00, 1.03, 1.05 Tasks: 234 total, 1 running, 233 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.7 us, 0.8 sy, 0.1 ni, 98.3 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8008768 total, 1189952 free, 731424 used, 6087392 buff/cache KiB Swap: 4194300 total, 4027180 free, 167120 used. 6567820 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 851 root 20 0 358320 48960 44148 S 1.3 0.6 280:19.41 sssd_nss 1187 root 20 0 2892624 47276 30112 S 0.7 0.6 233:30.07 fail2ban-s+ 26867 root 20 0 951764 49444 16424 S 0.7 0.6 2:55.12 qualys-clo+ 1 root 20 0 194644 5476 2904 S 0.3 0.1 36:14.81 systemd 517 root 20 0 39528 7228 6904 S 0.3 0.1 9:40.79 systemd-jo+ 777 dbus 20 0 88284 1952 1124 S 0.3 0.0 17:17.21 dbus-daemon 852 root 20 0 342868 7864 4916 S 0.3 0.1 7:50.13 sssd_pam 890 root 20 0 35772 1536 1344 S 0.3 0.0 30:38.36 cgrulesengd 2910 mweeks@+ 20 0 175224 2828 1948 R 0.3 0.0 0:00.14 top 2 root 20 0 0 0 0 S 0.0 0.0 0:05.00 kthreadd 4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+ 6 root 20 0 0 0 0 S 0.0 0.0 0:15.15 ksoftirqd/0 7 root rt 0 0 0 0 S 0.0 0.0 0:12.75 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 S 0.0 0.0 13:07.09 rcu_sched 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-dr+ 11 root rt 0 0 0 0 S 0.0 0.0 0:12.20 watchdog/0 [mweeks@gsuad.gsu.edu@snowball ~]$ cd /var [mweeks@gsuad.gsu.edu@snowball var]$ ls account cache db games kerberos local log nis preserve spool yp adm crash empty gopher lib lock mail opt run tmp [mweeks@gsuad.gsu.edu@snowball var]$ cd gopher/ [mweeks@gsuad.gsu.edu@snowball gopher]$ ls [mweeks@gsuad.gsu.edu@snowball gopher]$ cd .. [mweeks@gsuad.gsu.edu@snowball var]$ exit logout Connection to snowball.cs.gsu.edu closed. mweeks@air:unix_ch13$ exit exit Script done on Mon Dec 2 13:39:19 2024